Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change css of multiple elements

Tags:

jquery

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');
like image 808
Scarface Avatar asked Jan 04 '12 03:01

Scarface


2 Answers

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.

like image 156
Lightness Races in Orbit Avatar answered Oct 15 '22 14:10

Lightness Races in Orbit


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

like image 29
Shyju Avatar answered Oct 15 '22 13:10

Shyju