简体   繁体   English

使用jQuery删除特定的内联样式值。

[英]Remove a specific inline style value with jQuery.

I'd like to remove a specific inline color style from any tag wherever it may show up. 我想从任何可能出现的标签中删除特定的内联颜色样式。 The color is styled as style="color: rgb(255, 102, 0);". 颜色的样式为style =“color:rgb(255,102,0);”。

I was trying out testing with just the a tag but didn't get very far. 我正在尝试用一个标签进行测试,但没有走得太远。 Ideas? 想法? Not a Jquery person so I need a lot of help :). 不是Jquery的人,所以我需要很多帮助:)。

    $('a[style="color: rgb(255, 102, 0)"]').remove('[style="color: rgb(255, 102, 0)"]');

    $('a[style="color: rgb(255, 102, 0)"]').remove();

    <a style="color: rgb(255, 102, 0)">not orange</a>

    <a style="color: rgb(255, 102, 0);">not orange</a>

You may use this : 你可以用这个:

$('a[style="color: rgb(255, 102, 0)"]').css('color', '');

But this will only work if your style attribute is exactly "color: rgb(255, 102, 0)" . 但这只有在你的style属性正好是"color: rgb(255, 102, 0)"时才有效。

If you want something more reliable, for example accepting other style properties or a color specified in a CSS rule, you'd have to filter : 如果你想要更可靠的东西,例如接受其他样式属性或CSS规则中指定的颜色,你必须过滤:

$('a').filter(function(){
   return $(this).css('color')=='rgb(255, 102, 0)'
}).css('color', '');

Demonstration 示范

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM