<div class="box"></div>
<div class="box"></div> <!-- Hide -->
<div class="box"></div> <!-- Hide -->
<div class="box"></div> <!-- Hide -->
I need to hide all this div but not the first div.
I could do something like this:
jQuery('.box').hide();
jQuery('.box').first().show();
Is there a way to remove the first .box
from the array before .hide()
em?
Answer: Use the JavaScript substring() method You can use the JavaScript substring() method to remove first character form a string. A typical example is removing hash ( # ) character from fragment identifier.
The :first selector selects the first element. Note: This selector can only select one single element. Use the :first-child selector to select more than one element (one for each parent). This is mostly used together with another selector to select the first element in a group (like in the example above).
The jQuery empty() method removes the child elements of the selected element(s).
Definition and Usage. The :first-child selector selects all elements that are the first child of their parent. Tip: Use the :last-child selector to select elements that are the last child of their parent.
jQuery('.box').slice(1).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