I'm looking to hide all the li
elements except for the one with a specific index. I've written some code to achieve this, but I'm wondering if there's a simpler way using jQuery. While jQuery provides methods like eq
, gt
, and lt
, there isn't a built-in method for excluding a specific index.
$('#ulMenu').children("li:lt(2)").hide();
$('#ulMenu').children("li:gt(2)").hide();
$('#ulMenu').children("li:not(2)").hide(); //incorrect method