Bind event to element using pure Javascript -
i'm writing api , unfortunately need avoid jquery or 3rd party libraries. how events bound elements through jquery?
jquery example:
$('#anchor').click(function(){ console.log('anchor'); });
i'm close writing onclick attribute on element out of frustration, understand link between jquery event , dom element.
how element know fire jquery event when markup not changed? how catching dom event , overriding it?
i have created own observer handler cant quite understand how link element observer events.
here's quick answer:
document.getelementbyid('anchor').addeventlistener('click', function() { console.log('anchor'); });
every modern browser supports entire api interacting dom through javascript without having modify html. see here pretty bird's eye view: http://overapi.com/javascript
Comments
Post a Comment