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 trialMyles Gleeson
2,906 PointsWhy can't you access event.target directly?
$('.spoiler').on('click', 'button', function(event){
console.log(event.target);
// Show the spoiler text
$('.spoiler span').show();
// Hide "reveal spoiler" button
$(event.target).hide();
});
Why can't you hide the reveal spoiler button using simply event.target.hide() ?
Myles Gleeson
2,906 PointsSorry, the code was from the video before the challenge https://teamtreehouse.com/library/the-event-object-3
2 Answers
Justin Cantley
18,068 Points.hide() is a method that can only be called on a jQuery object.
Therefore, the only way to call .hide() on event.target is to first convert event.target into a jQuery object.
andren
28,558 PointsJustin Cantley's answer is right.
To reiterate hide
is a method that belongs to jQuery, it is not a method built into JavaScript's HTMLElement
object. That is why you cannot call it directly on event.target
.
Steven Parker
231,261 PointsThe methods and properties available on HTML elements are different from those on jQuery objects.
Here's a "direct" way to conceal an HTML element:
event.target.style.display = "none";
Steven Parker
231,261 PointsSteven Parker
231,261 PointsThe "View Challenge" button seems to link to an unrelated part of the course. Can you provide a link to the part that relates to this question?