Hacker News new | ask | show | jobs
by npongracic 4520 days ago
I think this is great, i was also thinking of replacing jquery functionality in some of my scripts with native methods and this helps me alot.

One question though, what is the pure javascript equivalent of $(document).on('click', '.selector', function() { // do something });

This is the new jquery .live() replacement and i need it because normal events stop working after async postbacks (eg. from an asp.net UpdatePanel).

Will this code do the trick if i attach it to the document element? Also i need IE8+ support :)

function addEventListener(el, eventName, handler) { if (el.addEventListener) el.addEventListener(eventName, handler) else el.attachEvent('on' + eventName, handler) }

addEventListener(el, eventName, handler)