Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Responding to User Interaction The Event Object

Joseph Anson
Joseph Anson
14,448 Points

Is it okay to choose !== ul or would e.target.tagName === 'LI' be the best option?

I paused the video to try to figure out how I would select the li inside the ul to make them uppercase/lowercase without using the for loop. It took me quite a long time but felt great having managed to do it! Then I watched the video and he did it differently, same result but different.

Here is my code:

const ul = document.querySelector('ul');


  ul.addEventListener('mouseover', (e) => {

    if (e.target !== ul) {
      e.target.textContent = e.target.textContent.toUpperCase();
    }
  });

  ul.addEventListener('mouseout', (e) => {
     if (e.target !== ul) {
      e.target.textContent = e.target.textContent.toLowerCase();
    }
  });

My question is, does it matter that I've used !== ul or should I be using the .tagName instead (i didn't even think about that unfortunately).

Thank you.

1 Answer

Steven Parker
Steven Parker
231,236 Points

The inequality test would be true for any other element, but testing the tag name guarantees that the rest of the code will only be applied to list items.