Skip to main content

Exercise 40

  • Create the following folder/file structure:
/ex_40
|-- index.html
<!DOCTYPE html>
<html>
<head>
<title>Events</title>
</head>
<body>
<div></div>
<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>

index.html

  • Create a basic HTML document
  • Create a script tag on the document head element
  • Select the link element and add a onmouseover event handler
  • Change the link style (background color) when the user hovers the link element using JavaScript
  • The background color must be:
    • First time: red
    • Second time: blue
    • Third time: green
    • Fourth time: gray
    • After four times: white
  • Add the link element a onmouseout event handler and show the following alert:
The link background color is: %backgroundColor%