javascript - Hide / Show multiple items with Jquery -


i have searched around , seem getting same answer people have asked similar question please forgive me if seems simplistic. trying hide/show multiple items @ same time pressing of 1 button, , seems way have come doing handling class, such below:

$(document).ready(function(){   $(".btn1").click(function(){     $("p").hide();   }); $(".btn2").click(function(){     $("p").show();   }); }); 

and html follows

<p class="test">if click on "hide" button, disappear.</p> <p class="test">if click on "hide" button, disappears.</p> 

i dont want using html selector

<p> 

as in example because want use different types of items.

what using css class?

  $(".btn1").click(function(){     $(".class-to-hide").hide();   }); 

html

<div class="class-to-hide">     <p>will hide</p> </div> <div>     <p class="class-to-hide">will hide</p> </div> 

there countless options use, familiar jquery selectors , take pick..

  • you use class, $('.something')
  • data-target="something", $('*[data-target="something"]')
  • input type="number", $('input[type="number"]')

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -