I have an unordered list (ul) and a few list's elements (li).
I'd like to bind all the li's except the last one.
Example:
$('ul li').on('click', someFunction);
$('ul li:last-child').off('click');
Using jQuery, is there a way to do it in one line of code?
Any help will be appreciated!
Yes, with the selector :not :
$('#elementName li:not(:last-child)').on('click', someFunction);
This selector should work:
$('#elementName li:not(:last-child)').on('click', someFunction);
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