In the following example code, I attach an onclick event handler to the span containing the text \"foo\". The handler is an anonymous function that pops up an <
onclick
There is another alternative: using setAttribute rather than adding an event listener. Like this:
setAttribute
Demo innerHTML and event listeners Click here.