Drawback for addEventListener Versus onClick Property

I understand the difference between the properties addEventListenerand onclickand know how to use both. I am wondering if there is feedback, always using EventListenerproperties instead onclick. EventListenerturns out to be much more powerful than just using onclickatleast when dynamically creating HTML from javascript.

Is there a lack of memory / processor or can I only use EventListeners?

+3
source share
1 answer

This is probably not the direction you are entering, but there are several cases where you cannot remove the event listener.

( ) :

// You do this
myLink.onclick = function () {
    alert('hello, world');
};

// Another developer who hates you because
// he thinks that you're hitting on his girlfriend
// but you're not, you're just friends, but
// he jealous so he doesn't understand
// does this
myLink.onclick = function () {
    alert('muahahahaha');
};

// Someone else could even get rid of
// the handler entirely:
myLink.onclick = null;

. - :

myLink.addEventListener('click', function () {
    alert('hello, world');
}, false);

. , , .

+3

All Articles