0

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?

1 Answer 1

1

You can do:

var selector = searches.join(", "); //Create concatenated selector

$(selector).click(function() {} )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.