I need to know how to use onclick so that it allows me to reuse the onclick method of a div over and over again and not have to add an infinite amount of them.
I don't want to have to do this:
<div id="div1" onClick="divFunction1()">
</div>
<div id="div2" onClick="divFunction2()">
</div>
<div id="div3" onClick="divFunction3()">
</div>
<div id="div4" onClick="divFunction4()">
</div>
But instead do something like this in JavaScript if possible:
div = document.getElementById("allPurposeDiv").onclick...
I'm not exactly sure what would come after onclick is the problem.
Any help is appriciated, Thanks!
document.getElementById("div1").onclick = whatever;