Answers for "how to add class name throufh js"

0

add classnames to body

openModal = (event) => {
  document.body.classList.add('modal-open');
  this.setState({ showModal: true });
}
hideModal = (event) => {
  document.body.classList.remove('modal-open');
  this.setState({ showModal: false });
}
Posted by: Guest on February-14-2020
0

how to add a class to an element in javascript

// 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");
Posted by: Guest on November-27-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language