Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery element filter by css

Tags:

I would like to select every div that has a red background color for example. is this possible in jquery?

<div style="background-color:red"></div>
<div style="background-color:white"></div>
<div style="background-color:red"></div>
<div style="background-color:yellow"></div>

thank you

like image 297
salmane Avatar asked May 11 '10 16:05

salmane


1 Answers

This code also works for CSS that is not defined in the style attribute of the tag:

$('div').filter(function() {
   return $(this).css('background-color') == 'red';
});
like image 121
Mathieu Rodic Avatar answered Oct 11 '22 21:10

Mathieu Rodic