-3

How can i hide multiple variables in jQuery?

Right now i have this :

$("#sub-total-value-v").hide();

I was trying to do something like this :

$("#sub-total-value-v").$("#sub-total-value-v2").$("#sub-total-value-v3").hide();

So i want to hide multiple variables in 1 line instead of copy edit and paste this : $("#sub-total-value-v").hide(); to $("#sub-total-value-v2").hide(); etc.

MissesSalima
  • 120
  • 10

2 Answers2

3

You can use comma , to separate selectors as follow.

$("#sub-total-value-v, #sub-total-value-v2, #sub-total-value-v3").hide();
Tushar
  • 85,780
  • 21
  • 159
  • 179
1

Use the starts with selector , for this kind of scenario

$("[id^=sub-total-value-v]").hide();
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Balachandran
  • 9,567
  • 1
  • 16
  • 26
  • 1
    Note: This is suitable when OP wants to hide ALL the elements having id starting with `sub-total-value-v` – Tushar May 26 '15 at 15:02