I’m creating html on runtime like this:
var myVar = "<div id='abc'>some clickable text</div>"
Now, I want to attach some event, say onclick, to this div. How can I do that on next line? I’ll add this to DOM later.
PS: I’ve to accomplish this without using JQuery.
Or you can use this technique: attach event to the
document.body. Then if the event target is not the needed div than just do nothing. It is the same techinque jquery uses for itslivefunction:Here is demo.