3

How do I select elements which have property color:lightGreen in CSS using jQuery and then change it to #666?

Example Html:

<a id="ctl00_ContentPlaceHolder1_GridView1_ctl17___ID_DetailsHyperLink" 
    class="CorporateHyperlink" 
     href="/EstimateSite/Estimate/Details.aspx?ID=234"
     style="color:LightGreen;">Details</a>
3
  • What type of elements are they? Can you post some HTML? Commented May 18, 2012 at 11:09
  • @AkshayKulkarni look at my answer just change $("p") to $("a") then it will apply to all anchor elements ... Commented May 18, 2012 at 11:56
  • The devil's in the details... literally in this case. ;) Commented Jul 23, 2012 at 22:11

3 Answers 3

6
$("a").each(function() {
    if ($(this).css("color") == "rgb(144, 238, 144)") {
        $(this).css("color", "#666");
    }
});

Or if you prefer using filter:

$("a").filter(function() {return $(this).css('color') == 'rgb(144, 238, 144)';})
.css("color", "#666");

BUT if you had the opportunity to edit the markup, you're best off adding the light green colour to a class, then applying the class to those elements, then you can have another class for your new colour, then change them like so:

$(".lightGreen").removeClass("lightGreen").addClass("newColour");
Sign up to request clarification or add additional context in comments.

1 Comment

What? I took the idea of replacing "lightGreen" to the RGB values, that was all. I'll +1 you for that how's that? :)
2

Try this:

$("div").each(function() {
    if ($(this).css("color") == "rgb(144, 238, 144)") {
        $(this).css("color", "#666");
    }
});

http://jsfiddle.net/z8Q5K/2/

It's working fine...

Comments

1
$("a").each(function() {
    if ($(this).css("color") == "rgb(144, 238, 144)") { 
        $(this).css("color", "#666");
    }
});

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.