Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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'
 
PREVIOUS NEXT
Tagged: #GET #CHANGE #class #element
ADD COMMENT
Topic
Name
9+8 =