JavaScript-On Click

Two examples of how to use onclick events.

by Susan Metoxen

HTML

<body>
  <h1>What Can JavaScript Do?</h1>
  <p id="content">JavaScript can change HTML content.</p>
  <button type="button" onclick="document.getElementById('content').innerHTML = 'Hello JavaScript!'">Click Me!</button>
<hr>
  <p id="size">JavaScript can change the style of an HTML element.</p>
  <button type="button" onclick="document.getElementById('size').style.fontSize='35px'">Click Me!</button>
</body>