+ 6

How to add multiple ids to a jquery tag

window.onload = moveHide(); function moveHide(){ $(function(){ $("#left").fadeToggle(0); }); $(function(){ $("#right").fadeToggle(0); }); $(function(){ $("#down").fadeToggle(0); }); $(function(){ $("#up").fadeToggle(0); }); $(function(){ $("#square").fadeToggle(0); }); } This is my code currently but it’s really wrong and there has to be a way to make it shorter. window.onload = moveHide(); function moveHide(){ $(function(){ $("#HOW TO PUT MULTIPLE IDS HERE").fadeToggle(0); });

3rd Feb 2018, 3:34 AM
Ole113
Ole113 - avatar
4 Respuestas
+ 15
resolved ! $("#left,#right,#down,#up,#square").fadeToggle(0);
3rd Feb 2018, 4:38 AM
Ranjan Bagri
Ranjan Bagri - avatar
+ 2
Thanks @Ranjan
3rd Feb 2018, 5:43 PM
Ole113
Ole113 - avatar
0
Use classes instead of IDs. An ID is supposed to be unique to a single element, but a class can be used on multiple elements. In jQuery and CSS you use . instead of # to select a class.
3rd Feb 2018, 4:35 AM
Tom Shaver
Tom Shaver - avatar
0
thanks!
3rd Feb 2018, 7:44 PM
Jan Verhoeven