Answers for "update class after change dom"

14

Javascript change element class

document.getElementById("myElementID").classList.add('myClassName');
document.getElementById("myElementID").classList.remove('myClassName');
Posted by: Guest on July-22-2019
0

GET and CHANGE the class of an element

const mssg = document.querySelector('p');//get the class of the p tag
console.log(mssg.getAttribute('class'));//the class is currently 'error'
mssg.setAttribute('class', 'success');//now the p tag's class is changed to 'success'
console.log(mssg.getAttribute('class'));//the new class of the p tag is 'success'
Posted by: Guest on December-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language