I have a code like this
$(".class1 .class2").on('click', function(){
//Do something
});
I am trying to somehting like this using variables:
var1=".class1";
var2=".class2"
$(var1 var2).on('click', function(){
//Do something
});
I see var1 and var2 are set to right values, but everytime I try to use 2 variables as selector it fails. When I keep the click trigger unchanged and use var1 or var2 elsewhere in the code individually (just var1 or var2 but not in the same selector list) it works. Any tips?
I figure I use var3 concatenate var1 and var2, but I am trying to reduce another variable.
var1 var2is not a list, it is a syntax error.... and even if it were a list, that list would be an object. Perhaps what you don't want is to pollute the name space, in that case, just do the concatenation inline as adeneo suggests.