Thanks for sharing.. Just want to add, using arrow function as eventListener callback will make the element lose the this context...
var span = document.querySelector('span'); span.addEventListener('click', (event) => { console.log(this); // Window Object }
compared to this
var span = document.querySelector('span'); span.addEventListener('click', function(event) { console.log(this); // Element Object this.innerHTML = 'Hola'; }
Budy, sorry but I don't notice any difference in the two snippets ... maybe the latter should be a regular function declaration such as "function(event) {...}" ? thank you, happy Easter!
Sorry, I've updated the snippet :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for sharing.. Just want to add, using arrow function as eventListener callback will make the element lose the this context...
compared to this
Budy, sorry but I don't notice any difference in the two snippets ... maybe the latter should be a regular function declaration such as "function(event) {...}" ?
thank you, happy Easter!
Sorry, I've updated the snippet :)