Answers for "how to add class to element on mouseclick with js"

0

how to add class to element on mouseclick with js

// element.classList.add("newClass");
// or
// element.className += "newClass";

// Example

document.querySelector("button").onclick = function addNewClass() {
  document.querySelector(".elementToChange").classList.add("newClass");
}
Posted by: Guest on May-09-2020

Code answers related to "how to add class to element on mouseclick with js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language