Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




JAVASCRIPT - EVENTS


Say, you have opened gmail, entered your userId and Password and clicked on submit. And bingo, you are in your inbox checking mail.


Or you have clicked any button in a website and a popup window opens.


So, after clicking the buttons, some action happens. These are called events in JavaScript.


Let us quickly jump into a practical example.


Example :



<html>
<body>
	
	<button onclick="testFunction()">Click ME</button>
    
	<script>
    	function testFunction() {
        	alert("Window popped up on click")
        }
	</script>      

</body>
</html>


Output :









So, in the above example, we have created a button and named it Click ME.


<button onclick="testFunction()">Click ME</button>

Now, if you see the button. It has an attribute called onclick, which calls a JavaScript Function called testFunction().


<script>
	function testFunction() {
		alert("Window popped up on click")
	}
</script>

Now this attribute onclick of button triggers an event.


In other words, some action gets triggered onclick and that is called Event.


Some of the popular Events are :

  1. onclick

  2. onmouseover

  3. onmouseout

  4. mousedown

  5. mouseenter

  6. mouseleave

  7. mousemove

  8. mouseover

  9. mouseout