SlideShare a Scribd company logo
www.webstackacademy.com ‹#›
Events
JavaScript
www.webstackacademy.com ‹#›

JavaScript Events

Event Flow

Event Types
Table of Content
www.webstackacademy.com ‹#›www.webstackacademy.com ‹#›
JavaScript Events
(JavaScript)
www.webstackacademy.com ‹#›
Events
ā—
An event is some notable action to which a script can respond. It
may be
– Click
– Mouseover
– Keystroke etc.
ā—
When a function is assigned to an event handler, that function is run
when that event occurs.
ā—
An Event handler is JavaScript code associated with a particular
part of the document and a particular event.
www.webstackacademy.com ‹#›
Event Handler
ā—
An Event handler is JavaScript code associated with a
particular part of the document and a particular event.
ā—
For example, an event handler associated with a button
could open a new window when the button is clicked.
ā—
A handler to the click event is called onclick.
www.webstackacademy.com ‹#›
Event Handler
ā—
Events are not limited to basic user-actions associated
with the document.
ā—
Browser supports events such as resize, load, and
unload.
www.webstackacademy.com ‹#›www.webstackacademy.com ‹#›
Event Flow
(JavaScript)
www.webstackacademy.com ‹#›
Event Flow
ā—
The order in which events are received on the web page
are described by event flow.
ā—
An event has three phases :
– Cycle
– Target
– Bubbling
www.webstackacademy.com ‹#›
Event Bubbling
ā—
Event Bubbling , the event is first captured and handled
by innermost element and then propagated to outer
element.
<html>
<body>
<ul>
<li>
<a>
www.webstackacademy.com ‹#›
Event Capturing
ā—
Event Capturing , the event is first captured by the outermost
element and propagated to the inner elements.
<html>
<body>
<ul>
<li>
<a>
www.webstackacademy.com ‹#›
Event Target
ā—
Event Capturing,it provides an opportunity to intercept
events if necessary.
ā—
Then the actual target receives the event.
ā—
Final phase is the bubbling , which allows a response to the
event.
www.webstackacademy.com ‹#›
Event Listeners
The DOM 2 level 2 define two methods:
– addEventListeners
– removeEventListeners
www.webstackacademy.com ‹#›www.webstackacademy.com ‹#›
Event Types
(JavaScript)
www.webstackacademy.com ‹#›
Mouse Events
Event Attribute Description
onclick Occurs when the mouse button is clicked
ondblclick Occurs when the mouse button is double clicked
onmousedown Occurs when the mouse button is pressed
onmouseup Occurs when the mouse button is released
onmousemove Occurs when mouse has moved while over an element.
onmouseover Occurs when mouse has moved over an element.
onmouseout Occurs when mouse has moved away from an element.
www.webstackacademy.com ‹#›
Keyboard Events
Event Attribute Description
onkeypress Occurs when a key pressed and released with focus on
element
onkeydown Occurs when a key pressed down
onkeyup Releases a key
www.webstackacademy.com ‹#›
Loading Events
Event Attribute Description
onload Occurs when element has loaded
onunload Indicates that browser is leaving the current document
onabort Occurs when the user abort the loading of an image
www.webstackacademy.com ‹#›
Selection and Focus Event
Event Attribute Description
onselect Occurs after some text has been selected in an element
onchange Occurs when text input has been changed
onfocus Indicates that an element has received focus
onblur Occurs when an element losses focus
www.webstackacademy.com ‹#›
Other Events
Event Attribute Description
onresize User resizes a window or a frame
onsubmit Indicates form submission by clicking a submit button
onreset Indicates that form is being reset by clicking reset
button
www.webstackacademy.com ‹#›
Events Example
<body>
<button onclick="show()">Click Here</button>
<p id="ex"></p>
<script>
function show() {
document.getElementById("ex").innerHTML = "Hello World";
}
</script>
</body>
www.webstackacademy.com ‹#›
Events Example
<!DOCTYPE html>
<html>
<body onLoad="alert('Welcome to my page!');"
onUnload="alert('Goodbye! Sorry to see you go!');">
<img src="birdflying.GIF">
</body>
</html>
www.webstackacademy.com ‹#›
Events Example
<script>
function OnMouseIn (elem) {
elem.style.border = "4px solid green";
}
function OnMouseOut (elem) {
elem.style.border = "";
}
</script>
</head>
<body>
<div style="background-color:#ddf0af; width:300px;color:#800000"
onmouseover="OnMouseIn (this)" onmouseout="OnMouseOut (this)">
Move your mouse pointer into and out of this element!
</div>
</body>
www.webstackacademy.com ‹#›
Event Listeners
ā—
The method addEventListeners() is used to register a single event
listener on the document.
ā—
These methods exist on all DOM nodes. There is a slight change in event
naming convention also, compared to how they are used with button
elements (ex: onclick vs click)
ā—
The event type to listen for (eg: mouseout, click, error etc)
ā—
The event handler function to be executed when the event is occurs.
ā—
The third parameter is a boolean value specifying whether to use event
bubbling or event capturing. This parameter is optional.
ā—
The keyword this used with event handler represents a reference to the
HTML element which fired the event handler.
www.webstackacademy.com ‹#›
Event Listeners
Syntax :
element.addEventListener(event, function, useCapture);
ā—
We can add many event handlers to one element.
ā—
We can add many event handlers of the same type to one element, i.e
two "click" events.
ā—
We can easily remove an event listener by using the
removeEventListener() method.
www.webstackacademy.com ‹#›
Event Listeners Example
www.webstackacademy.com ‹#›
Exercise
ā—
Write a JavaScript program to create a paragraph and background color must
change after some mouse events:
+ onclick button → yellow
+ odblclick button → blue
+ onmouseout → green
+ onmouseover → red
ā—
Write a JavaScript program to create a text field and show the effect of some
events:
+ onchange
+ onfocus
+ onblur
www.webstackacademy.com ‹#›
Web Stack Academy (P) Ltd
#83, Farah Towers,
1st floor,MG Road,
Bangalore – 560001
M: +91-80-4128 9576
T: +91-98862 69112
E: info@www.webstackacademy.com

More Related Content

What's hot (20)

PPTX
Event In JavaScript
ShahDhruv21
Ā 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
Ā 
PPSX
Javascript variables and datatypes
Varun C M
Ā 
PPTX
Java script
Shyam Khant
Ā 
PDF
Basics of JavaScript
Bala Narayanan
Ā 
PPT
Javascript
mussawir20
Ā 
PDF
3. Java Script
Jalpesh Vasa
Ā 
PPTX
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
Ā 
PPT
JavaScript Tutorial
Bui Kiet
Ā 
PPTX
Javascript 101
Shlomi Komemi
Ā 
PDF
JavaScript Programming
Sehwan Noh
Ā 
PPT
Java Script ppt
Priya Goyal
Ā 
PDF
Javascript and DOM
Brian Moschel
Ā 
PDF
Html frames
eShikshak
Ā 
PPTX
ReactJS presentation.pptx
DivyanshGupta922023
Ā 
PPT
Introduction to Javascript
Amit Tyagi
Ā 
PPT
JavaScript: Events Handling
Yuriy Bezgachnyuk
Ā 
PPTX
jQuery PPT
Dominic Arrojado
Ā 
PPTX
jQuery
Dileep Mishra
Ā 
Event In JavaScript
ShahDhruv21
Ā 
Lab #2: Introduction to Javascript
Walid Ashraf
Ā 
Javascript variables and datatypes
Varun C M
Ā 
Java script
Shyam Khant
Ā 
Basics of JavaScript
Bala Narayanan
Ā 
Javascript
mussawir20
Ā 
3. Java Script
Jalpesh Vasa
Ā 
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
Ā 
JavaScript Tutorial
Bui Kiet
Ā 
Javascript 101
Shlomi Komemi
Ā 
JavaScript Programming
Sehwan Noh
Ā 
Java Script ppt
Priya Goyal
Ā 
Javascript and DOM
Brian Moschel
Ā 
Html frames
eShikshak
Ā 
ReactJS presentation.pptx
DivyanshGupta922023
Ā 
Introduction to Javascript
Amit Tyagi
Ā 
JavaScript: Events Handling
Yuriy Bezgachnyuk
Ā 
jQuery PPT
Dominic Arrojado
Ā 
jQuery
Dileep Mishra
Ā 

Similar to JavaScript - Chapter 11 - Events (20)

PDF
Web 5 | JavaScript Events
Mohammad Imam Hossain
Ā 
PPTX
Upstate CSCI 450 WebDev Chapter 9
DanWooster1
Ā 
PPTX
JavaScript_Events.pptx
Yagna15
Ā 
PPTX
DHTML - Events & Buttons
Deep Patel
Ā 
PPTX
Javascript event handler
Jesus Obenita Jr.
Ā 
PPT
Document_Object_Model_in_javaScript..................................ppt
rahamatmandal2005
Ā 
PDF
jQuery -Chapter 2 - Selectors and Events
WebStackAcademy
Ā 
PPTX
Javascript 2
pavishkumarsingh
Ā 
PDF
Introducing jQuery
Grzegorz Ziolkowski
Ā 
PDF
JavaScript From Scratch: Events
Michael Girouard
Ā 
PPTX
GDG On Campus NBNSCOE Web Development Workshop Day 2 : JavaScript and DOM
udaymore742
Ā 
PPTX
types of events in JS
chauhankapil
Ā 
PPTX
JavaScript_Event_Handling_Updated_______
Captain81145
Ā 
PPTX
5 .java script events
chauhankapil
Ā 
PPTX
Web programming
Subha Selvam
Ā 
KEY
Events
Josh Guo
Ā 
PPTX
Learn Javascript Basics
Khushiar
Ā 
PPTX
javascript-events_zdgdsggdgdgdsggdgdgd.pptx
NetajiGandi1
Ā 
PDF
Javascript Browser Events.pdf
ShubhamChaurasia88
Ā 
ODP
Event handling using jQuery
Iban Martinez
Ā 
Web 5 | JavaScript Events
Mohammad Imam Hossain
Ā 
Upstate CSCI 450 WebDev Chapter 9
DanWooster1
Ā 
JavaScript_Events.pptx
Yagna15
Ā 
DHTML - Events & Buttons
Deep Patel
Ā 
Javascript event handler
Jesus Obenita Jr.
Ā 
Document_Object_Model_in_javaScript..................................ppt
rahamatmandal2005
Ā 
jQuery -Chapter 2 - Selectors and Events
WebStackAcademy
Ā 
Javascript 2
pavishkumarsingh
Ā 
Introducing jQuery
Grzegorz Ziolkowski
Ā 
JavaScript From Scratch: Events
Michael Girouard
Ā 
GDG On Campus NBNSCOE Web Development Workshop Day 2 : JavaScript and DOM
udaymore742
Ā 
types of events in JS
chauhankapil
Ā 
JavaScript_Event_Handling_Updated_______
Captain81145
Ā 
5 .java script events
chauhankapil
Ā 
Web programming
Subha Selvam
Ā 
Events
Josh Guo
Ā 
Learn Javascript Basics
Khushiar
Ā 
javascript-events_zdgdsggdgdgdsggdgdgd.pptx
NetajiGandi1
Ā 
Javascript Browser Events.pdf
ShubhamChaurasia88
Ā 
Event handling using jQuery
Iban Martinez
Ā 
Ad

More from WebStackAcademy (20)

PDF
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
Ā 
PDF
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
Ā 
PDF
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
Ā 
PDF
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
Ā 
PDF
Webstack Academy - Internship Kick Off
WebStackAcademy
Ā 
PDF
Building Your Online Portfolio
WebStackAcademy
Ā 
PDF
Front-End Developer's Career Roadmap
WebStackAcademy
Ā 
PDF
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
Ā 
PDF
Angular - Chapter 7 - HTTP Services
WebStackAcademy
Ā 
PDF
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
Ā 
PDF
Angular - Chapter 5 - Directives
WebStackAcademy
Ā 
PDF
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
Ā 
PDF
Angular - Chapter 3 - Components
WebStackAcademy
Ā 
PDF
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
Ā 
PDF
Angular - Chapter 1 - Introduction
WebStackAcademy
Ā 
PDF
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
Ā 
PDF
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
Ā 
PDF
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
Ā 
PDF
JavaScript - Chapter 5 - Operators
WebStackAcademy
Ā 
PDF
JavaScript - Chapter 3 - Introduction
WebStackAcademy
Ā 
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
Ā 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
Ā 
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
Ā 
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
Ā 
Webstack Academy - Internship Kick Off
WebStackAcademy
Ā 
Building Your Online Portfolio
WebStackAcademy
Ā 
Front-End Developer's Career Roadmap
WebStackAcademy
Ā 
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
Ā 
Angular - Chapter 7 - HTTP Services
WebStackAcademy
Ā 
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
Ā 
Angular - Chapter 5 - Directives
WebStackAcademy
Ā 
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
Ā 
Angular - Chapter 3 - Components
WebStackAcademy
Ā 
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
Ā 
Angular - Chapter 1 - Introduction
WebStackAcademy
Ā 
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
Ā 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
Ā 
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
Ā 
JavaScript - Chapter 5 - Operators
WebStackAcademy
Ā 
JavaScript - Chapter 3 - Introduction
WebStackAcademy
Ā 
Ad

Recently uploaded (20)

PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
Ā 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
Ā 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
Ā 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
Ā 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
Ā 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
Ā 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
Ā 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
Ā 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
Ā 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
Ā 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
Ā 
PDF
Kit-Works Team Study_20250627_ķ•œė‹¬ė§Œģ—ė§Œė“ ģ‚¬ė‚“ģ„œė¹„ģŠ¤ķ‚¤ė§(ģ–‘ė‹¤ģœ—).pdf
Wonjun Hwang
Ā 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
Ā 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
Ā 
PPTX
Digital Circuits, important subject in CS
contactparinay1
Ā 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
Ā 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
Ā 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
Ā 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
Ā 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
Ā 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
Ā 
Mastering Financial Management in Direct Selling
Epixel MLM Software
Ā 
The Project Compass - GDG on Campus MSIT
dscmsitkol
Ā 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
Ā 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
Ā 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
Ā 
How do you fast track Agentic automation use cases discovery?
DianaGray10
Ā 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
Ā 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
Ā 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
Ā 
Kit-Works Team Study_20250627_ķ•œė‹¬ė§Œģ—ė§Œė“ ģ‚¬ė‚“ģ„œė¹„ģŠ¤ķ‚¤ė§(ģ–‘ė‹¤ģœ—).pdf
Wonjun Hwang
Ā 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
Ā 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
Ā 
Digital Circuits, important subject in CS
contactparinay1
Ā 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
Ā 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
Ā 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
Ā 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
Ā 

JavaScript - Chapter 11 - Events