SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
Jussi Pohjolainen
 

Tendances (20)

Java script
Java scriptJava script
Java script
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Datatype in JavaScript
Datatype in JavaScriptDatatype in JavaScript
Datatype in JavaScript
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom event
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Javascript event handler
Javascript event handlerJavascript event handler
Javascript event handler
 
JavaScript: Events Handling
JavaScript: Events HandlingJavaScript: Events Handling
JavaScript: Events Handling
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
jQuery
jQueryjQuery
jQuery
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
Dom
DomDom
Dom
 

Similaire à JavaScript - Chapter 11 - Events

Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9
DanWooster1
 
Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2
kshyju
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
Faisal Aziz
 

Similaire à JavaScript - Chapter 11 - Events (20)

Javascript Browser Events.pdf
Javascript Browser Events.pdfJavascript Browser Events.pdf
Javascript Browser Events.pdf
 
JavaScript_Events.pptx
JavaScript_Events.pptxJavaScript_Events.pptx
JavaScript_Events.pptx
 
Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9
 
Javascript #8 : événements
Javascript #8 : événementsJavascript #8 : événements
Javascript #8 : événements
 
DHTML - Events & Buttons
DHTML - Events  & ButtonsDHTML - Events  & Buttons
DHTML - Events & Buttons
 
Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
5 .java script events
5 .java script   events5 .java script   events
5 .java script events
 
types of events in JS
types of events in JS types of events in JS
types of events in JS
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
Events.pdf
Events.pdfEvents.pdf
Events.pdf
 
Asp.net event handler
Asp.net event handlerAsp.net event handler
Asp.net event handler
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
The Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingThe Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event Handling
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
 
Dive into javascript event
Dive into javascript eventDive into javascript event
Dive into javascript event
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPF
 
Html5 events
Html5 eventsHtml5 events
Html5 events
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 

Plus de WebStackAcademy

Plus de WebStackAcademy (20)

Webstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement JourneyWebstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement Journey
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per SecondWSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per Second
 
WSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer CourseWSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer Course
 
Career Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and Opportunities
 
Webstack Academy - Internship Kick Off
Webstack Academy - Internship Kick OffWebstack Academy - Internship Kick Off
Webstack Academy - Internship Kick Off
 
Building Your Online Portfolio
Building Your Online PortfolioBuilding Your Online Portfolio
Building Your Online Portfolio
 
Front-End Developer's Career Roadmap
Front-End Developer's Career RoadmapFront-End Developer's Career Roadmap
Front-End Developer's Career Roadmap
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase Integration
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

JavaScript - Chapter 11 - Events