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

Jonathan Aldas
Jonathan Aldas
2,421 Points

It's not working.

it's selecting the correct tag because it spits it out to the console but it does not want to work?

listDiv.addEventListener("mouseover", (e) => {

  if(e.target.tagName == 'LI'){
  console.log(e.target.tagName);
    e.target = e.target.textContent.toUpperCase();
  }
});
listDiv.addEventListener("mouseout", (e) => {
  if(e.target.tagName == 'LI'){
  console.log(e.target.tagName);
    e.target = e.target.textContent.toUpperCase();
  }
});
Owa Aquino
Owa Aquino
19,277 Points

Hi Jonathan,

Can you add how you selected the listDiv on your code. That will much help us to understand your problem.

And is there any reason why you have the same condition when you mouseover and mouseout?

Cheers!

Jonathan Aldas
Jonathan Aldas
2,421 Points

Yes, I only want to execute the code when I move the mouse on a LI

const listDiv = document.querySelector(".list");
Jonathan Aldas
Jonathan Aldas
2,421 Points

Never Mind I found the solution. Thank You

Owa Aquino
Owa Aquino
19,277 Points

Great job! So what was it?

Trent Stenoien
Trent Stenoien
Full Stack JavaScript Techdegree Graduate 20,034 Points

Looks like you already found the answer, but here's the solution for anyone else wondering. I believe so anyway.... haha!

Right now you are redefining the entire e.target object; you need to be more specific. If you add '.textContent' before the = you will have better results.

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

Some methods will return a value you need to store in a new variable (like this one), others will just modify the thing you're calling it on (like document.write()).