简体   繁体   中英

Get the next page and previous page from pagination UL

I have a php code which generates pagination links.

I have ol > li list..

li has titles like Page 1, page 2, next page, previous page, last page, first page

I want only the links -> Previous Page and Next Page .. So I can use jQuery and search within li

Using this, I get all the links. [Used binded click to know check if the ]

jQuery(document).ready(function(){
jQuery('#custom_pagination li').find('li').attr('title','Next Page').click(function(){alert("clicked");})
});

I only want 2 of them with searching the title attr. HOw do i do it.?

tx

With .attr( attributeName, value ) , you are setting the atrribute on every li !

See: http://api.jquery.com/attr/

.attr( attributeName, value ) attributeNameThe name of the attribute to set. valueA value to set for the attribute.

You need to only select the LI's with the right title. See below:

Similar problem: Get element by title jQuery

Solution:

$("li[title='Next Page'],li[title='Previous Page']").click(function(){alert("clicked");})

Updated answer:

$("#custom_pagination").find("a[title='Next Page'],a[title='Previous Page']").click(function(){alert("clicked");})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM