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
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.
Use :last-child selector together with .is()
$('#c').is(':last-child')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With