0 votes
in JavaScript by
What are events in javascript?

1 Answer

0 votes
by

Events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can react on these events. Some of the examples of HTML events are,

  1. Web page has finished loading
  2. Input field was changed
  3. Button was clicked

Let's describe the behavior of click event for button element,

<!doctype html>
<html>
 <head>
   <script>
     function greeting() {
       alert('Hello! Good morning');
     }
   </script>
 </head>
 <body>
   <button type="button" onclick="greeting()">Click me</button>
 </body>
</html>
...