Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics Understanding jQuery Events and DOM Traversal The Event Object

seth aruby
seth aruby
9,291 Points

console.log(event.target) returning multiple results, not single button that was clicked

When I preview this code and log 'event.target' to the console, it is returning two results, not one for the button I clicked. Anybody?... here's my code, from what i can tell it is just like hers. Thanks for help...

$('.spoiler').on('click', 'button', function(event) {

console.log(event.target);

$('.spoiler span').show();
$(event.target).hide();

});

//create buttons on page

const $button = $('<button>Reveal Spoiler</button>');

$('.spoiler').append($button);

//hide span text (spoiler) on page load

$('.spoiler span').hide();

seth aruby
seth aruby
9,291 Points

Also, at the end she states "you'll see now that when you click a button, only the button we've clicked disappears" but its very clear in the video that she's clicking the top button and the bottom button is disappearing. Is the top button actually getting removed and the bottom one is shifting into its place so it only appears like the bottom button is getting removed?

1 Answer

Steven Parker
Steven Parker
215,960 Points

About 4 minutes into the video she says, "However, both spoilers are still revealed,..."

And shortly after she says, "We'll fix that issue in an upcoming video"

seth aruby
seth aruby
9,291 Points

Not sure if you watched the rest of the video but right after that she comments out the code that is causing 'that issue', refreshes the page and then says "you'll see now that when you click a button, only the button we've clicked disappears" which doesn't appear to be the case. Also, if you know why I'm getting multiple results on the console.log(event.target) instead of just one that would be helpful. I actually switched out 'event.target' with 'event.currentTarget' and that seemed to work but not sure if it is 'right'.

Steven Parker
Steven Parker
215,960 Points

To facilitate a complete analysis, make a snapshot of your workspace (while it's in the state that demonstrates the issue) and post the link to it here.