+ 3
[Solved] Javascript Functions to add event on html element
button.onclick = function (){} Or.. button.onclick = () => {} And . button.addEventListener("click", function(){}) What's difference between these three styles. Which one will be more practical and good to use. Drop ur ideas.😀
2 Respuestas
0
Use first one, since you need to do removeEventListener for avoid memory leak. In 2 varian this context will be bad since arrow func has no this context., 3 variant just like lamda function so remove event listener couls not call
0
Please see here for an example how can be it done:
https://code.sololearn.com/W2mTAN2s05qW/?ref=app