So, I know, if I use the selector more than once, it is better to cache it in a javascript variable. What if I want to perform the same action for multiple jQuery selectors that are stored in variables? ex
var $selector1 = $('
var $selector2 = $('
var $selector3 = $('
//do some work here on each individual div
//now I want to do this
$('#div1, #div2, #div3').addClass('myClass');
Is there a way to do this on three variables? (something like
($selector1, $selector2, $selector3).addClass('myClass');)
source
share