how to add class to element on mouseclick with js

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

// Example

document.querySelector("button").onclick = function addNewClass() {
  document.querySelector(".elementToChange").classList.add("newClass");
}
Source

Also in JavaScript: