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>
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>
Share
Improve this question
edited May 29, 2012 at 16:48
Mathew Thompson
56.4k15 gold badges129 silver badges150 bronze badges
asked May 18, 2012 at 11:08
MaxRecursionMaxRecursion
4,90112 gold badges44 silver badges77 bronze badges
3
- What type of elements are they? Can you post some HTML? – Mathew Thompson 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 ... – Code Spy Commented May 18, 2012 at 11:56
- The devil's in the details... literally in this case. ;) – Jagd Commented Jul 23, 2012 at 22:11
3 Answers
Reset to default 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");
Try this:
$("div").each(function() {
if ($(this).css("color") == "rgb(144, 238, 144)") {
$(this).css("color", "#666");
}
});
http://jsfiddle/z8Q5K/2/
It's working fine...
$("a").each(function() {
if ($(this).css("color") == "rgb(144, 238, 144)") {
$(this).css("color", "#666");
}
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744720345a4589871.html
评论列表(0条)