How to apply jquery command to multiple divs?

Let's say I want to hide multiple divs at once.

$("#something").click(function() {
  $("#one").hide();
  $("#two").hide();
  $("#three").hide();
});

How can I reduce the middle three lines to one line?

+4
source share
3 answers
$('#one, #two, #three').hide();

or give them a class and hide everything at once

$('.class').hide();
+2
source

Just add such a comma

$("#one, #two, #three").hide();
+2
source

Just comma separate them :)

$("#something").click(function() {
  $("#one, #two, #three").hide();
});
+2
source

Source: https://habr.com/ru/post/1628405/


All Articles