I'm learning javascript, and I've seen more than one way of registering click events:
$(DOMelement).click(function() {});
$(DOMelement).on('click',function() {});
(DOMelement).addEventListener('click', function() {});
Can someone tell me what's the best practice for event registration? Or the major advantage/disadvantage of each one? I'm asuming on() and click() are very similar, but since I'm just getting started I would like to know which is the most used so I can start writing efficient code from the start. Also, is it still a good practice to do the html onclick registration?
<button onclick="function()"></button>
$(DOMelement).addEventListenerisn't a function.addEventListeneris a native DOM Element function and you must unwrap the element from jQuery to use it:$(DOMelement)[index].addEventListener