1

is it possible to assign CSS styles through jQ to several selectors in one statement like it can be done through pure CSS?

var foo = $('#thisEl');
var boo = $('#thatEl');

[foo and boo].css({
...CSS here
});
1
  • Yes. Basically any selector you can use in CSS you can also use as a jQuery selector. Commented Nov 23, 2013 at 3:46

1 Answer 1

2

You you can use multiple selectors

$('#thisEl, #thatEl').css({
...CSS here
});

or if you have references to jQuery wrapper object only then use .add() to create a new combined jQuery wrapper

var foo = $('#thisEl');
var boo = $('#thatEl');

foo.add(boo).css({
...CSS here
});
Sign up to request clarification or add additional context in comments.

1 Comment

btw, would foo.add(boo).add(goo).css({... work if you want 3 or more elements?

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.