I am totally new to Javascript. But I learned a little about Activescript before. I was taught to use addEventListener to handle events.
But when I come to JavaScript, although addEventListener is an option, it seems a minor way to use addEventListener. Instead, people use onChange().
Except syntactically, are there any behavioural differences?
I was also taught to always use removeEventListener. It seems not very necessary. If I use onChange, there is no need to code removeEventListener?
Thank you
Two main differences :
With addEventListener
you can attach multiple event listeners. This is not true of the onchange
attribute.
I personally think addEventListener is a lot of better. An example you can do with this in HTML5
document.addEventListener("input", function(){
target = window.event.target.value;
window.event.target.nextSibling.nextSibling.value = target*2;
});
<input name="1" value="25">
<input name="2" value="50" readonly>
<p>Hello World</p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With