Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery live() in plain JavaScript?

Tags:

jquery

live

I am trying to accomplish what the jQuery live() function can do, but in plain JavaScript. Can anyone here help with this?

Thanks!

like image 432
PropSoft Avatar asked Dec 09 '10 23:12

PropSoft


1 Answers

Here is a little startup example

document.onclick = function(evt){

    evt =  evt  ||  window.event;
    var element = evt.target  ||  evt.srcElement;

};

wherever you click you get a reference to the element that received the click.

More useful, though, in a real scenario would be to use the attachEvent method for IE, or the addEventListener for the rest.

like image 55
Gabriele Petrioli Avatar answered Sep 19 '22 12:09

Gabriele Petrioli