JavaScript Events - Introduction to events



HTML Events

  • An HTML event can be something the browser does, or something a user does.
  • Here are some examples of HTML events:
    • An HTML web page has finished loading
    • An HTML input field was changed
    • An HTML button was clicked
  • Often, when events happen, you may want to do something.
  • JavaScript lets you execute code when events are detected.
  • HTML allows event handler attributes, with JavaScript code, to be added to HTML elements.
javascript-events

Sample Code

<!DOCTYPE html>
<html>
<body>

<button onclick="document.getElementById('demo').innerHTML=Date()">The time is?</button>

<p id="demo"></p>

</body>
</html>

Output

The time is?
Thu Dec 01 2022 17:57:49 GMT+0530 (India Standard Time)

Related Searches to JavaScript Events - Introduction to events