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
 

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)

PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PDF
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PPTX
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Kubernetes - Architecture & Components.pdf
geethak285
 
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 

JavaScript - Chapter 11 - Events