Answers for "js apply class on click"

0

click on div with class javascript

<!--In html:-->
<div class="myDiv with_this_class" > any text </div>
<script>
  var divClicked = document.querySelector('.myDiv.with_this_class').click();
</script>
Posted by: Guest on November-24-2020
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

Browse Popular Code Answers by Language