Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining if the element is the last child of its parent

Tags:

jquery

Using jQuery, is there a quick way of knowing if an element is its parent's last child?

Example:

<ul>   <li id="a"></li>   <li id="b"></li>   <li id="c"></li> </ul>  $('#b').isLastChild(); //should return FALSE $('#c').isLastChild(); //should return TRUE 
like image 874
cambraca Avatar asked Nov 17 '10 22:11

cambraca


People also ask

What is last child?

The :last-child selector allows you to target the last element directly inside its containing element. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content.


1 Answers

Use :last-child selector together with .is()

$('#c').is(':last-child') 
like image 198
Rafael Avatar answered Nov 11 '22 08:11

Rafael