Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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");
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: can i use hooks with expo in react native 
Javascript :: operador ternario angular click 
Javascript :: javascript troubleshooting with jest 
Javascript :: react steam auth 
Javascript :: await reserved word testcafe using await in loop 
Javascript :: next.js google script 
Javascript :: backbone js event listener 
Javascript :: how to exclude required files from grunt merge 
Javascript :: get every other item in an array 
Javascript :: what is code.jquery integrity crossorigin 
Javascript :: AWS SDK for javascript assumerole with proxy 
Javascript :: what is the modern syntax for iterating through array using for loop in javascript 
Javascript :: apollo graphql clearstore example 
Javascript :: restful react npm 
Javascript :: how to compare a string with its ending in javascript 
Javascript :: sumoselect select all option 
Javascript :: go back doesnt load javascript safari 
Javascript :: how to get state value from history react 
Javascript :: convert json in parse inputs azure function 
Javascript :: javascript compute heading on too points 
Javascript :: .env file vars nto defined in child directory 
Javascript :: elemente alphabetisch sortieren javascript 
Javascript :: what is @ atsign in first of file path nodejs 
Javascript :: nesting in Jinja2 expressions 
Javascript :: react native map array of objects 
Javascript :: ssh tunnel connect to mongodb in node.js 
Javascript :: 380/2 
Javascript :: get switchery to load after an ajax call 
Javascript :: mongodbClint express 
Javascript :: trigger click on each element of class 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =