0

I have that div

<div style='width:20px; height:20px; background-color:COLORNAME'></div>

which is created in the for loop.

Lets say I want to find the div which background color is #0000FF. How to do it by jquery ?

2 Answers 2

3

How about using:

$("[style*='background-color:#0000ff']");

Bear in mind, that it's based on string comparison, so spaces (and case) will matter.

A fiddle: http://jsfiddle.net/eithe/6mwD7/

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

Comments

1

The browser will always process the color and output it as an rgb value, so this should do:

$('div').filter(function(){
    return $(this).css('background-color') == 'rgb(0, 0, 255)';
});

JSFiddle

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.