Umesh Moghariya
Umesh Moghariya

Reputation: 3183

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

Upvotes: 1

Views: 427

Answers (1)

Derk Arts
Derk Arts

Reputation: 3460

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");})

Upvotes: 1

Related Questions