JavaScript JavaScript and the DOM Responding to User Interaction The Event Object

jmac pd
jmac pd
8,253 Points

VS Code says 'event' use like this is deprecated

What is the alternative using 'e' as a param in the function and replacing event with 'e'? what's the difference? haha

listDiv.addEventListener('mouseover', (e) => {
  if (e.target.tagName == 'LI') {
  e.target.textContent = e.target.textContent.toUpperCase();
  }
});

listDiv.addEventListener('mouseout', (e) => {
  if (e.target.tagName == 'LI') {
    e.target.textContent = e.target.textContent.toLowerCase();
  }
});

1 Answer

jmac pd
jmac pd
8,253 Points

Thanks for posting. I think I get it it. Just best practice to add as a parameter and avoid global variables in a function?