...

Web Technologies - JAVASCRIPT

Back to Course

Lesson Description


Lession - #210 Javascript Events


JavaScript's interaction with HTML is handled through events that occur when the user or the browser manipulates a page. When the page loads, it is called an event. When the user clicks a button, that click too is an event. Other examples include events like pressing any key, closing a window, resizing a window, etc.javascript event loops are also it consist.


There are 8 different types of events in javascript list


1.User interface events.
2.Focus and blur events.
3.Mouse events.
4.javascript Keyword events.
5.Form events.
6.Mutation events and observers.
7.HTML5 events.
8.CSS events.
9.javascript keycode event.



Syntax

With single quote


<element event='some javascript'>

with double quotes


<element event="some javascript">


Here is a list of a few common Javascript events:

Event Description
onchange An HTML element has been changed
onclick The user clicks a HTML element
onmouseover The user moves the mouse over a HTML element
onmouseout The user moves the mouse away from a HTML element
onkeydown The user pushes a keyboard key
onload The browser has finished loading the page


Let's see an example


<!DOCTYPE html>
<html>
<body>

<h2>JavaScript HTML Events</h2>
<p>Click the button to display the date.</p>

<button onclick="displayDate(>
">The time is?</button> <script> function displayDate(>
{ document.getElementById("demo">
.innerHTML = Date(>
; } </script> <p id="demo"></p> </body> </html>

Output


Try it here