Chapter09 JavaScript2UsingJavaScript
Chapter09 JavaScript2UsingJavaScript
JavaScript
Chapter 9
3 Events
4 Event Types
5 Forms
6 Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 9
The Document
1 2
Modifying the
Object Model DOM
(DOM)
3 Events
4 Event Types
5 Forms
6 Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Document Object Model (DOM)
Overview
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Document Object Model (DOM)
Nodes and NodeLists
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Document Object Model (DOM)
Document Object
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Document Object Model (DOM)
Selection Methods
Classic
• getElementById()
• getElementsByTagName()
• getElementsByClassName()
Newer
• querySelector() and
• querySelectorAll()
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Document Object Model (DOM)
Selection Methods
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Document Object Model (DOM)
Query Selector
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Document Object Model (DOM)
Element Node Object
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Document Object Model (DOM)
More common (not universal) properties
• href
• name
• src
• value
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 9
The Document
1 2
Modifying the
Object Model DOM
(DOM)
3 Events
4 Event Types
5 Forms
6 Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Modifying the DOM
Changing an Element’s Style
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Modifying the DOM
Meet the family
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Modifying the DOM
Changing an Element’s Content
document.getElementById("here").innerHTML =
"foo<em>bar</em>";
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Modifying the DOM
Creating DOM elements
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Modifying the DOM
Creating DOM elements
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Modifying the DOM
Tools - Debuggers
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Modifying the DOM
Tools – Performace checkers
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Modifying the DOM
Tools – Linters
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 9
The Document
1 2
Modifying the
Object Model DOM
(DOM)
3 Events
4 Event Types
5 Forms
6 Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Events
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Events
Event-Handling Approaches – Inline Hook
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Events
Event-Handling Approaches – Event Property Approach
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Events
Event-Handling Approaches – Event Listener Approach
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Events
Event-Handling Approaches – Event Listener Approach (anon function)
myButton.addEventListener('click', function() {
var d = new Date();
alert("You clicked this on "+ d.toString());
});
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Events
Event Object
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Events
Event Object
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 9
The Document
1 2
Modifying the
Object Model DOM
(DOM)
3 Events
4 Event Types
5 Forms
6 Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Event Types
Mouse Events
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Event Types
Keyboard Events
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Event Types
Touch Events
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Event Types
Form Events
• Blur
• Change
• Focus
• Reset
• select
• Submit
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Event Types
Frame Events
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 9
The Document
1 2
Modifying the
Object Model DOM
(DOM)
3 Events
4 Event Types
5 Forms
6 Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Forms
Responding to Form Movement Events
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Forms
Responding to Form Changes Events
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Forms
Validating a Submitted Form
• Field Validation
• Number Validation
• Other (non JavaScript) Form validation reminder
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Forms
Submitting Forms
var formExample =
document.getElementById("loginForm");
formExample.submit();
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
AJAX
First the Normal Request Response Loop
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
AJAX
The problem
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
AJAX
The solution
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 9
The Document
1 2
Modifying the
Object Model DOM
(DOM)
3 Events
4 Event Types
5 Forms
6 Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Summary
Key Terms
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Summary
Questions?
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.