MaxRecursion
MaxRecursion

Reputation: 4893

Select elements which have color:lightGreen in CSS using jQuery

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>

Upvotes: 3

Views: 2082

Answers (3)

thecodeparadox
thecodeparadox

Reputation: 87073

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

Upvotes: 1

Mathew Thompson
Mathew Thompson

Reputation: 56429

$("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");

Upvotes: 6

Owais Iqbal
Owais Iqbal

Reputation: 549

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...

Upvotes: 2

Related Questions