12

I just want to know if instead of

$(".element1").css('background','#000');
$(".element2").css('background','#000');

It is possible to concatinate multiple elements to have them affected by one command or if there is a more efficient way like so:

$(".element1",".element2").css('background','#000');
2

2 Answers 2

26

CSS selectors have always supported unions:

$(".element1, .element2").css('background','#000');

You can also add to the jQuery element set yourself:

$(".element1").add(".element2").css('background','#000');

All you needed was a cursory glance at the documentation.

Sign up to request clarification or add additional context in comments.

Comments

3

$(".element1,.element2").css('background','#000'); will do

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.