-
Notifications
You must be signed in to change notification settings - Fork 321
Home
I've been asked a couple times, "How do we start the homework?" The instructions start off with "When I click..." That's an indication that we should be doing something with a click
event. We can't modify the HTML, so we'll have to use addEventListener
to attach a click
event to the button.
The reason the instructions hint about event.preventDefault()
is that the default click
action for <button></button>
is to reload the page (as if it was submitting a form). So the event listener you add to <button>
won't work, because the page will be reloading.
Finally, I really like putting all my JS in the <head>
. However, that requires an onload
attribute on <body>
. The <body>
in this HTML doesn't have onload
, and we're not allowed to touch the HTML. So we'll need to rely on the fact that the JS has been included at the end of <body>
.
So your code should start off something like this:
- Get the button element
- Add a
click
event listener to it - Prevent the default
click
event from happening - Continue on to add the new stuff you want to happen