Im trying to figure out if i have several paragraphs, how can I when the specific object is clicked, make an alert on just that one.
For example, heres my code:
HTML
<div id="myDiv">StackOverflow</div>
<div id="myDiv">StackOverflow</div>
JS
document.getElementById("myDiv").onclick = function() { alert(this.innerHTML) };
What this code does, it that only the first element pops up.. I know I can do another function but im trying to do this with just one and have no idea.. I know that an ID is unique and should not be used more than once, but how can i do this if a div is created dynamically by a user and whenever they click on a specific div of it, the div should alert with a popup.