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)"))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #add #onclick #multiple #elements
ADD COMMENT
Topic
Name
3+1 =