Reputation: 3501
I have this idea where I want to check if the class exists when the button is clicked, but using an array that way I don't have to write it like this:
$(".example1,.example2,.example3,.example4,.example5").click(function() {
myClass = $(this).attr("class").split(' ')[2];
BtnRank = $(this).index('button');
alert('BtnRank: '+BtnRank+' '+myClass);
return false;
});
Instead it would look like this:
var searches = ['.example1','.example2','.example3','.example4','.example5'];
What's the best approach to make this work properly?
Upvotes: 0
Views: 26
Reputation: 104775
You can do:
var selector = searches.join(", "); //Create concatenated selector
$(selector).click(function() {} )
Upvotes: 1