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!

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 Asynchronous Programming with JavaScript Asynchronous JavaScript with Callbacks Implement a Callback

Button removal

The final function towards the end of the video has me somewhat confused: btn.addEventListener('click', (event) => { getJSON(astrosUrl, (json) => { json.people.map(person =>{ getJSON(wikiUrl + person.name, generateHTML); }); }); event.target.remove(); });

How is event.target.remove() removing the button?

Hi James, You set a listener on the btn. You told the listener to react when the btn is clicked.


The 'event' is an object created when the listener detects the click.


The 'event' object contains a property called 'target', which is a reference to the btn (The object which caused the event).


The .remove() method is called on the 'event.target' - effectively removing the btn which caused the event.

1 Answer

Thanks for breaking it down Phil. Its targeting the element targeted by the click. Got it. Thanks.

No problem James, glad I could help.