删除包含以下样式的所有类

时间:2016-06-27 06:13:29

标签: javascript jquery firefox greasemonkey

如何删除包含以下样式的所有类?

HTML

<div class="viewed" style="background:#F9F0D5">
   <div class="left">
        <span class="title">My </span>
            <p>MPA </p>
    </div>
    <div class="right">
        <span>5</span>
    </div>
</div>

代码示例

document.getElementsByClassName('viewed')[0].style.background:#F9F0D5)[0].remove();

4 个答案:

答案 0 :(得分:0)

Javascript解决方案 Demo Fiddle

pkgbuild

你已经标记了jQuery,所以使用jQuery选择器,

var viewed = document.querySelectorAll('.viewed[style="background:#F9F0D5"]');

for(i=0;i<viewed.length;i++){
    viewed[i].classList.remove('viewed');
}

要删除元素,

$('.viewed[style="background:#F9F0D5"]').removeClass('viewed');

答案 1 :(得分:0)

您好参考此https://plnkr.co/edit/FxemUZMAmEqo2oXvvMXN?p=preview

$(".viewed[style='background:#F9F0D5']").remove();

这是语法

$('div[style*=block]').removeAttr('style');

答案 2 :(得分:0)

看一下附件摘录。

$(".viewed").each(function() {
  var finalres=$(this).attr('style');
   $(this).removeClass('viewed');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="viewed" style="background:#F9F0D5">
  <div class="left">
    <span class="title">My </span>
    <p>MPA</p>
  </div>
  <div class="right">
    <span>5</span>
  </div>
</div>
<div class="viewed" style="background:#F9F0D6">
  <div class="left">
    <span class="title">My </span>
    <p>MPA</p>
  </div>
  <div class="right">
    <span>5</span>
  </div>
</div>

答案 3 :(得分:0)

可能这就是你要找的东西吗?

m=3

def f(x): 
    global m
    m=m+1
    return m*x

初始*可以由特定选择器替换。 但是如果要删除包含该样式的元素的所有类,或者为您的示例2选项 1)

$("*[style*='backlground:#F9F0D5']").removeClass()

2)

$("div[style*='backlground:#F9F0D5']").removeClass()

我希望这有助于你