Is there a one lined way to hide all of a certain type of elements in one selector. I know you could do this:
$('p').hide();
$('p:first(or :eq(0)').show()
Possibly something like this:
$('p:eq(>0)')
slice()
will probably give the best performance:
$('p').slice(1).hide();
...where 1
is the second element in the results and 0
would be the first. This is faster because it uses native methods instead of a custom filter.
Alternatively, you could use :not()
or .not()
:
$('p:not(:first)').hide();
//or $('p').not(':first').hide();
http://jsfiddle.net/x6DEY/
$("p").not(":first").hide();
This should work too but is ugly:
$("div:not(:first)").hide();
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