Introduction to Events in JavaScript

Introduction to Events in JavaScript

ยท

2 min read

Events

๐Ÿ‘‰ Events are actions or occurrences done by the user that happens in the system, and as a result the code will trigger a desire react to those events.

๐Ÿ‘‰ When JavaScript is written with HTML, JavaScript can react to those HTML elements.

Why do we need Events ?

๐Ÿ‘‰ Events are required to track user movements when he/she is looking into the website.

๐Ÿ‘‰ Events also help us to produce a output in respect to the user inputs and deliver him/her the desired result.

Here are some Common Events ๐Ÿ‘‡

onChange

๐Ÿ‘‰ Executes a JavaScript when a user changes the selected option of a element.

<select onchange="myFunction()">

onClick

๐Ÿ‘‰ The onClick() event executes a JavaScript when a user clicks on an element.

<button onclick="myFunction()">Click me</button>

onMouseOver

๐Ÿ‘‰ The onMouseOver event occurs only when the user moves the mouse pointer onto an element, or onto one of it's children.

<img onmouseover="bigImg(this)" src="smiley.gif" alt="Smiley">

onMouseOut

๐Ÿ‘‰ The onMouseOut event occurs only when the user moves the mouse pointer out of an element, or out from one of it's children

<img onmouseout="normalImg(this)" src="smiley.gif" alt="Smiley">

onKeyDown

๐Ÿ‘‰ The onKeyDown event occurs when the user presses a key in the website.

<input type="text" onkeydown="myFunction()">

onLoad

๐Ÿ‘‰ The onLoad event is executed when an object has been loaded.

๐Ÿ‘‰ The onLoad event can be used to deal with the cookies of the website

๐Ÿ‘‰ It can also be used to check visitor's browser type and browser type.

<body onload="myFunction()">

If you liked my content, connect with me? ๐Ÿ˜ƒ

github linkedin twitter

ย