Skip to content

Latest commit

 

History

History
32 lines (29 loc) · 767 Bytes

ex_37.md

File metadata and controls

32 lines (29 loc) · 767 Bytes

Exercise 37

  • Create the following folder/file structure:
/ex_37
  |-- 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 body element and add the keypress event handler
  • When the user press a key we'll show the following message on the console
You pressed the %pressedKey% key with the %charCode% code
  • Use event.charCode & String.fromCharCode() to get the key and code