I want to check the li
that is the last li
in ul
. How can I check that using jQuery?
Just use the following
if($('#ulscroller li:last-child')[0] == liTocheck)
{
alert("This is the last li");
}
Or
if($('#ulscroller li').last()[0] == liTocheck)
{
alert("This is the last li");
}
Here liTocheck
is the li that needs to be compared
You can use the .last()
matcher
$('#ulscroller li').last()
Just use the :last-child selector :
$('#ulscroller li:last-child')
DEMO: http://jsfiddle.net/f5v6R/
For example, if you want to know if it has the selected
class you may do
if ($('#ulscroller li:last-child').hasClass('selected')) {
// do something
}
$('ul#ulscroller').children('li').last();
http://api.jquery.com/last/
You could also do it like so:
$('ul#ulscroller').children('li:last-child');
http://api.jquery.com/last-selector/
Here's an example to illustrate it: http://jsfiddle.net/TheNix/W92vF/
try this
$(function(){
alert($('#ulscroller li:last-child').val());
})