Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

onclick add class javascript

<div class="cl1">test</div>
<button onlick="change()">change</button>

// javaScript part 
let elemnt = document.getElementsByClassName("cl1")
function change(){
// "add" is gonna add classe one time if you click again class is not gonna remove if you want to change class and remove it with 2 click use toggle
// add
  elemnt.classList.add("cl2")
// toggle
  elemnt.classList.toggle("cl2")
}
Comment

add class on javascript onclick function

document.addEventListener('click', function handleClick(event) {
  console.log('user clicked: ', event.target);

  event.target.classList.add('bg-yellow');
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: js switch case greater than 
Javascript :: javascript prompt to integer 
Javascript :: how to get the min value of two variables in math 
Javascript :: js substring 
Javascript :: await set timeout 
Javascript :: javascript execute code on page load 
Javascript :: give the player an item skript 
Javascript :: shuffling in js 
Javascript :: windows.load with settimeout 
Javascript :: mongoose connection 
Javascript :: how to set validation for email in javascript 
Javascript :: deploy react app netlify 
Javascript :: javascript get current week number 
Javascript :: display image base64 in REACT NATIVE 
Javascript :: react query devtools 
Javascript :: javascript round decimal 
Javascript :: cy url contains 
Javascript :: react proptypes reuse shape 
Javascript :: combine two arrays javascript 
Javascript :: get day name from date javascript 
Javascript :: prevent form from reloading with preventDefault 
Javascript :: how to delete the last part of a string in node js 
Javascript :: change mouse highlight color js 
Javascript :: A form label must be associated with a control react 
Javascript :: canada postal code regex 
Javascript :: redirect to website javascript 
Javascript :: replace node 
Javascript :: javascript date get minutes with leading zero 
Javascript :: jquery enable disable textbox 
Javascript :: remove space from string javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =