如何移除活動類。下面是我的代碼,第一個我覺得ID標籤,則class但是這個代碼不工作:如何在javascript中移除標籤子類的類別
function myFunction() {
var element1 = document.getElementById('grid3d');
var remove_class = 'active';
element1.className = element1.className.replace(' ' + remove_class, '').replace(remove_class, '');
}
.active {
color: red;
}
<div id="grid3d">Hello World
<figure ">Click the button to remove the class attribute from the h1 element.</figure>
<figure class="active ">Click the button to remove the class attribute from the h1 element.</figure>
<figure>Click the button to remove the class attribute from the h1 element.</figure>
</div>
<button onclick="myFunction() ">Try it</button>
使用jquery它只有兩行代碼// ex $(「element1」)。removeClass(「active」); –
我已更新我的代碼 –
給你的代碼 –