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
logan vanetten
6,252 Pointsif (e.target.tagName == 'LI') .... so how come this handler isn't filtering out all but the list iteams?
nothing more
<!DOCTYPE html>
<html>
<head>
<title>JavaScript and the DOM</title>
</head>
<link rel="stylesheet" href="style.css" />
<body>
<section>
<h1>Making a Webpage Interactive</h1>
<p>JavaScript is an exciting language that you can use to power web servers, create desktop programs, and even control robots. But JavaScript got its start in the browser way back in 1995.</p>
<hr>
<p>Things to Learn</p>
<ul>
<li>Item One: <input type="text"></li>
<li>Item Two: <input type="text"></li>
<li>Item Three: <input type="text"></li>
<li>Item Four: <input type="text"></li>
</ul>
<button>Save</button>
</section>
<script src="app.js"></script>
</body>
</html>
let section = document.getElementsByTagName('section')[0];
section.addEventListener('click', (e) => {
if (e.target.tagName == 'LI') {
e.target.style.backgroundColor = 'rgb(255, 255, 0)';
}
});
4 Answers
Steven Parker
244,128 PointsWhat makes you think it's not filtering?
The filtering seems to work as expected. When I click on the list items, the background color changes, and when I click any other section elements it does not.
The problem seems to be that the list items are not what the challenge asked for. The challenge said to limit the event handling to the INPUT elements. So the filtering is indeed working, just on the wrong things.
Jason Anello
Courses Plus Student 94,610 PointsHi Logan,
The challenge wants the inputs to trigger the background change. Not the list items.
Steven Wegner
9,351 PointsI'm a bit confused as to why INPUT needs to be in all caps.
logan vanetten
6,252 PointsIt returns every thing in caps. INPUT is not equal to Input. if its <p> you put P, if its <li> you put LI, ect...
if (e.target.tagName == 'LI') /////// e.target.tagName returned targeted tagName in caps
Daniel Stangaciu
6,221 PointsHey guys, just a quick question! Why it needs to be in all caps the tag name? which function or i dont know what transforms the tag name in caps?
logan vanetten
6,252 Pointslogan vanetten
6,252 PointsI am not saying it lol "Bummer! Make sure you are filtering out the right elements." tree-house is?
Steven Parker
244,128 PointsSteven Parker
244,128 PointsI didn't see the challenge link before, but now that it's there I can see this is a case of something that "works" but performs a different task than the one requested.
logan vanetten
6,252 Pointslogan vanetten
6,252 PointsOH limit the INPUT..... lol i got you