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 jQuery Basics Understanding jQuery Events and DOM Traversal The Event Object

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();

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
229,732 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"

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
229,732 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.