I'm using the following code to set all classes of the element to display:none with the exception of the first instance.
How would I modify the code to set the classes all the elements todisplay:none with the exception of the SECOND instance only.
$(document).ready(function () {
$('selectorForElement').slice(1).css('display', 'none');
});
A conjunction of :not() and :eq() selectors should do it:
$('.selectorForElement:not(:eq(1))').hide();
Live demo.
$('selectorForElement:eq(0), selectorForElement:gt(1)').css('display', 'none');
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