Exercise 35
- Create the following folder/file structure:
/ex_35
|-- index.html
index.html
- Create a basic HTML document
- Create a script tag on the document head element
- Add the following html code
<!DOCTYPE html>
<html>
<head>
<title>Events</title>
</head>
<body>
<button id="firstButton">Click Me!!</button>
<button id="secondButton">Remove event listener</button>
<a href="https://google.com">Link with JavaScript handler</a>
</body>
</html>
- Copy and paste exercise 34 code
- Add a link element like the one in html example
- Select the link element using
querySelector
method - Add the link element an click event handler using
addEventListener
- When the user clicks on the link we need to prevent the default behaviour
- Show the following message using alert
This link doesn't send us to a differen page as we're preventing the default behaviour