How to use Event in JavaScript

In this article I am going to explain about Event in JavaScript
  • 2290

JavaScript Event

Event is an message that send by an object to single occurrence action. Action can be caused  user interaction or triggered some program logic such as mouse click, button click, mouse hover, page load etc. An event are normally use for combine with function. when event occur then function will be call. An event has ability by which we can create dynamic web page.

Types of event

  • onClick - onClick event generate when user click on mouse.
  • onMouseHover - onMouseHover enent generate when mouse hover on field.
  • onSubmit - onSubmit event generate when we submit the form.
  • onLoad - onLoad event generate when we enter or leave the page.
  • onChange - onChange event generate when we change content of text field (onChange often use with combination of validation).

Example

In this example we are using button click event.

<html>

 

<head>

<script type="text/javascript">

    function myFunction() {

        document.getElementById("demo").innerHTML = Date();

    }

</script>

</head>

 

<body>

<h5 id="demo" ></h5>

 

<button type="button" onclick="myFunction()">click me</button>

 

</body>

</html>

Output

event.jpg

Further Readings

You may also want to read these related articles: here
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.