Reputation: 4893
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
Reputation: 87073
$("a").each(function() {
if ($(this).css("color") == "rgb(144, 238, 144)") {
$(this).css("color", "#666");
}
});
Upvotes: 1
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
Reputation: 549
Try this:
$("div").each(function() {
if ($(this).css("color") == "rgb(144, 238, 144)") {
$(this).css("color", "#666");
}
});
It's working fine...
Upvotes: 2