Skip to main content

Adding interactivity with javascript

Use javascript (js) in html

You can define javascript directly in html:

<script>
// script content here...
</script>

Or you can import a javascript from some link:

<script type="text/javascript" src="jquery-3.3.1.js"></script>

Example

<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script >
    function handleClick() {
      alert("You clicked on the button!");
    }
  </script>
</head>
<body>
  <button onclick="handleClick()">Click me </button>
</body>
</html>

Live view