I'm dynamically creating some <div>
elements and then filling their innerHTML
properties with text. I'm trying to set their onclick
event handlers like this:
myDiv.onclick = function() { alert("Hello!") };
That I can do. What I would like to do is be able to access the value / innerHTML (new to Javascript and DOM, so I'm unsure of what term is what I'm looking for) within the newly defined onclick
function. How would I go about accessing the data of myDiv
within the function being defined for its onclick
property? myDiv
will be something simple like:
<div>StackOverflow</div>
Any help would be greatly appreciated!