I have the following:
<div id="elementor-tab-title-1141" class="elementor-tab-title elementor-active">
...some stuff...
</div>
I need a JavaScript code to look for all elements with that class, and remove the “elementor-active”. So the code, after the JavaScript runs on page load, should look like this:
<div id="elementor-tab-title-1141" class="elementor-tab-title">
...some stuff...
</div>
Here is what I tried:
function changeClass()
{
var classNameArray= document.getElementsByClassName("elementor-tab-title elementor-active");
for(var i = (classNameArray.length - 1); i >= 0; i--)
{
classNameArray[i].innerHTML =
getClassName(classNameArray[i].innerHTML);
classNameArray[i].className = "elementor-tab-title";
}
}
Thanks!
2
Answers
You can use
querySelectorAll()
to target all the elements, then loop through them to remove class usingclassList.remove()
from the element:Follow the below steps
querySelectorAll()
to get all the elements with thatclass
forEach()
loop on all the elementsclassList.remove()
to remove that particular classUsing jQuery
You can do that bit easier using jQuery
removeClass()