Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 236
MaxRecursion Avatar asked May 15 '26 01:05

MaxRecursion


1 Answers

$("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");
like image 87
mattytommo Avatar answered May 16 '26 16:05

mattytommo