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 Adding New Elements to the DOM

I did not understand why we are creating a button in this way?

Button is already created, why we are creating in different way?

2 Answers

Adam Cameron
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Adam Cameron
Python Web Development Techdegree Graduate 16,731 Points

If a user pulls up the page and their JavaScript doesn't load/doesn't work for whatever reason, the <button> won't work for them because the stuff controlling it is in our app.js (which isn't working for this user). Terrible user experience, in fact the app completely fails for that user.

On the other hand, if we make the presence of the button dependent on JavaScript working in the first place, then the worst thing that can happen for a user is they don't get to experience the fun of pressing the button and 'revealing' the spoiler for themselves. But at least they still get to see the spoiler. Does that make sense?

Steven Parker
Steven Parker
231,007 Points

The JavaScript button is associated with a different functionality than the button already present from HTML. So the code shown in the video replaces the other button with the new one. The advantage of having the HTML button there to start with is for cases where JavaScript is not supported by the user's browser (or disabled by their settings).