Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript add onclick to multiple elements

const arrayOfElements = document.querySelectorAll(".classNameToAddOnClickTo")
arrayOfElements.forEach(x => x.setAttribute("onclick", "methodToCall(this.id)"))
 
PREVIOUS NEXT
Tagged: #javascript #add #onclick #multiple #elements
ADD COMMENT
Topic
Name
2+8 =