本文介绍了在CSS中使用jQuery选择具有颜色的元素:lightGreen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在CSS中使用jQuery选择具有属性 color:lightGreen
的元素,然后将其更改为#666
?
How do I select elements which have property color:lightGreen
in CSS using jQuery and then change it to #666
?
示例Html:
<a id="ctl00_ContentPlaceHolder1_GridView1_ctl17___ID_DetailsHyperLink"
class="CorporateHyperlink"
href="/EstimateSite/Estimate/Details.aspx?ID=234"
style="color:LightGreen;">Details</a>
推荐答案
$("a").each(function() {
if ($(this).css("color") == "rgb(144, 238, 144)") {
$(this).css("color", "#666");
}
});
或者如果您喜欢使用 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");
这篇关于在CSS中使用jQuery选择具有颜色的元素:lightGreen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!