AddClass JS Vanilla
element.classList.add('className');
web-noob master
element.classList.add('className');
var element = document.getElementById('element');
element.classList.add('class-1');
element.classList.add('class-2', 'class-3');
element.classList.remove('class-3');
document.addEventListener("DOMContentLoaded", function() {
var faqContainers = document.getElementsByClassName('faq-container')
var faqToggle = document.getElementsByTagName('body')[0]
for (var i = 0; i < faqContainers.length; i++) {
faqContainers[i].addEventListener('click', function() {
if (faqToggle.classList.contains('faq-display')) {
faqToggle.classList.remove('faq-display')
} else {
faqToggle.classList.add('faq-display')
}
})
}
})
var someElement= document.getElementById("myElement");
someElement.className += " newclass";//add "newclass" to element (space in front is important)
const element = document.querySelector('CSS_SELECTOR')
element.classList.add('class-1') // add class-1
element.classList.remove('class-1') // remove class-1
element.classList.toggle('class-1') // add class-1 if the element does not contains the class, remove if not.
// This is to add a class to any html element after you store it
// in the element variable
element.classList.add("my-class-name");
// This is to remove a class from the element
element.classlist.remove("my-class-name");