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 trialKevin Gamboa
Front End Web Development Techdegree Graduate 14,958 Pointsconst checkbox = event.target;.... event is crossed out in VS?
Hi all!
Im using VS as my workspace for this lesson.
I noticed by following Guil's codes on my end, the 'event' has a strike-through, but its working no problem.
My code as of below:
ul.addEventListener('change', (e)=>{
const checkbox = event.target;//event has strike-through here on my VS
const checked = checkbox.checked;
const listItem = checkbox.parentNode.parentNode;
if (checked) {
listItem.className = 'responded';
} else {
listItem.className = '';
}
});
Can someone help explain why the strike-through appears even though the code works just fine?
Thanks!
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Kevin Gamboa! So, here's the thing about the event
object. In Safari, Edge, and Chrome it is global. Meaning everything has access to the event
. This wasn't true of Firefox for a very long time. Now it is, but you would have to enable certain settings within Firefox to make it so.
I believe this was just a typo that works in most browsers and most browsers will understand this by default. However, the event
object was passed in using the variable name e
for the parameter. So, to be consistent, (and have VS Code quit complaining), you should use e.target
instead of event.target
. Alternatively, you could change the e
at the top to event
. Either one should work!
Hope this helps!
kkellerman
15,633 PointsIts a way to show that its deprecated
Kevin Gamboa
Front End Web Development Techdegree Graduate 14,958 PointsKevin Gamboa
Front End Web Development Techdegree Graduate 14,958 PointsThank you Jennifer for the awesome explanation, fully understand it now.
Stefan G
5,388 PointsStefan G
5,388 PointsJust noticed that he's using "event" instead of "e" and was going to post a question because I didn't know why is it working. Thanks for the explanation.