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

Amy Tomey
Amy Tomey
8,923 Points

please explain why the 'LI' has to be capitalized in the if statement?

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

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

1 Answer

Brandon White
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

Hi Amy,

If you were to log the event.target.tagName to your console, the string that was logged would be all caps. That’s the reason why you use all caps when your checking in the if statement.