Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to avoid looping for accessing each element except the first child

<div class="container">
   <div class="row m-0 be_product_grid_image">
      <divclass="col_classes">
      <img src="img1.png" />
   </div>
   <div class="row m-0 be_product_grid_image">
      <divclass="col_classes">
      <img src="img2.png" />
   </div>
   <div class="row m-0 be_product_grid_image">
      <divclass="col_classes">
      <img src="img3.png" />
   </div>
   <div class="row m-0 be_product_grid_image">
      <divclass="col_classes">
      <img src="img4.png" />
   </div>
   <div class="row m-0 be_product_grid_image">
      <divclass="col_classes">
      <img src="img5.png" />
   </div>
</div>

I want to show all images except the first image on clicking the ‘show allbutton
similarly hide all images except first image on clicking ‘show lessbutton

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

var images = $('.be_product_grid_image:not(:first)');

$(document).on('click', 'your_show_all_button', function() {
     images.show()
})

$(document).on('click', 'your_show_less_button', function() {
     images.hide()
})

Try applying this method by replacing your_show_all_button and your_show_less_button with your buttons’ class or id

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading