Answers for "add dynamic class in javascript w3c"

89

js add class

var element = document.getElementById('element');
element.classList.add('class-1');
element.classList.add('class-2', 'class-3');
element.classList.remove('class-3');
Posted by: Guest on May-07-2020
9

javascript add class

// getting the target element
var myElement = document.querySelector('#myElement');

// example for addding some-class to the element
myElement.classList.add('some-class');

// multiple classes can be added like this
myElement.classList.add('one-class', 'one-more-class');

// example for removing any class from the element
myElement.classList.remove('any-class');
Posted by: Guest on September-02-2020
2

dynamically change css class with javascript

document.getElementById('idOfElement').classList.add('newClassName');
Posted by: Guest on September-26-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language