Reacting to User Input

  • To react to user inputs, HTML elements should trigger JavaScript functions
  • One way to do this is to create a function and reference it in an HTML attribute
  • Remember that JavaScript has two separate steps - Defining a function and calling it
<html>
    <body>
        <button onclick="handleClick()">Click Me</button>
        <script>
            function handleClick() {
                console.log("Button was clicked")
            }
        </script>
    </body>
</html>

23 / 24