I can not modify the XHTML whatsoever. Strictly from the JavaScript itself how do I detect the ID of the element that is clicked? I'd like to set it to a variable. So for example if I assign the variable to alert, if the user clicks on "hb2" it will set the variable's value to "hb2", alert, and can be repeated. The script needs to be able to reassign the variable's value every time a new ID is detected.
So window.onload we want JavaScript to listen for .onclick. The problem for me is I still am unaware of how to detect the ID of the element being clicked!
The method accepts a single parameter which is an event object. Some browsers supply a global event object, therefore don't actually pass in that parameter. The event object references the element firing the event.
XHTML and CSS I can follow the terminology just fine, but I'm still working on JavaScript. I need some sort of code I can reference online and mess around with.
This is what I'm guessing you're hinting at. Still I don't see the connection to actually getting the ID. If I can get the ID I should be able to execute the script with little or no trouble. What is the usecapture for?
There are two separate things: event methods and addEventListener. I referred to both. The first response was about the latter, while the second response was about the former.
I appreciate the help though I'm really not a conceptual person at such a raw level, do you have any material examples that can give me a visual of what you're talking about? I'm looking up what you're mentioning (terminology really), throwing it in with what I'm looking for (.onclick, this, etc) and I'm surprised I haven't found anything that relates to dynamically determining the id of an element that has been clicked.
Thank you for the good example, it at least shows the behavior of the script I desire. If I can get it to alert the ID I should be able to assign it to a variable just fine.
However the code itself only works at the bottom of the page and also only works with div elements. I want to be able to select any element by it's ID. I can understand needing to set a separate function in conjunction with addEventListener but I don't have any concept of how to approach is correctly.