jhon de jhon de - 5 months ago 11
Javascript Question

Remove all classes which contain following style

how do i remove all classes which contain the following style...

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>


code sample

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

Answer

Javascript solution Demo Fiddle :

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

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

You have tagged jQuery, so using jQuery selectors,

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

To remove the element,

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