SlideShare a Scribd company logo
1 of 25
Programming Web Pages with JavaScript
Objectives
Explore the Document Object Model
Access elements and properties using
JavaScript
Create statements
Store and access data in variables
2HTML5 and CSS3 – Illustrated, 2nd
Edition
Objectives (continued)
Create a function
Add an event listener
Change CSS with JavaScript
Create an if statement
3HTML5 and CSS3 – Illustrated, 2nd
Edition
Explore the Document
Object Model
JavaScript: the most widely used
programming language for modern
web browsers
Document Object Model (DOM):
standardized way of referring to parts
of a web page
 Creates a hierarchical arrangement
known as a DOM tree
 Each part of HTML document
represented by a node
4HTML5 and CSS3 – Illustrated, 2nd
Edition
Explore the Document
Object Model (continued)
Object: HTML element in DOM
 Specific object must be identified in order
to manipulate it using JavaScript
Property: piece of a standard set of
information associated with DOM
node
 Attributes are considered their own
nodes and are associated with their own
properties
5HTML5 and CSS3 – Illustrated, 2nd
Edition
Explore the Document
Object Model (continued)
Method: action that can be performed
for a node
 Method names are followed by
parentheses between which you specify
information specific to the method
 querySelector() method lets you
access any HTML element by specifying
a CSS selector
• Example:
querySelector("#nameinput") selects
the element with the id value nameinput
6HTML5 and CSS3 – Illustrated, 2nd
Edition
Explore the Document
Object Model (continued)
A DOM Tree
7HTML5 and CSS3 – Illustrated, 2nd
Edition
Access Elements and
Properties Using JavaScript
querySelector() method lets you
reference objects and properties
 querySelector() is a child of the
Document object
To use a method, specify its parent
object, a period, and method name:
document.querySelector()
8HTML5 and CSS3 – Illustrated, 2nd
Edition
Access Elements and Properties
Using JavaScript (continued)
Specify CSS selector within
parentheses of method to reference
an object
 To select the aside element:
document.querySelector("aside")
To access a property, add dot and
property name after method:
document.querySelector("aside").textContent
9HTML5 and CSS3 – Illustrated, 2nd
Edition
Access Elements and Properties
Using JavaScript (continued)
Console: part of developer tools in
modern browsers; can be used to
enter test code and view error
messages related to JavaScript
The browser console in Chrome:
10HTML5 and CSS3 – Illustrated, 2nd
Edition
Create Statements
Statement: a JavaScript instruction
that performs an action:
Assignment operator (=): Part of a
statement that lets you assign a new
property value
 Code on left of = accesses property
 Code on right of = specifies new value
• often enclosed in quotes
11HTML5 and CSS3 – Illustrated, 2nd
Edition
Create Statements
(continued)
Every JavaScript statement ends with
a semicolon (;)
Statements created in external
JavaScript file
 Text file with .js extension
 Referenced within HTML document using
script element
12HTML5 and CSS3 – Illustrated, 2nd
Edition
Create Statements
(continued)
Statements added to file:
script element in HTML document:
13HTML5 and CSS3 – Illustrated, 2nd
Edition
Store and Access Data in
Variables
Variables: Stored values you can
access with a name you specify
 Can store many types of information
 Create with var keyword followed by
name, equal sign, and value:
14HTML5 and CSS3 – Illustrated, 2nd
Edition
Store and Access Data in
Variables (continued)
Shorter statements easier to work with
 Common to store object references as
variables, then reference in other
statements using variable names:
15HTML5 and CSS3 – Illustrated, 2nd
Edition
Create a Function
Function: Group of one or more
statements with an assigned name
 Statements in function referenced as a
single unit
 Create with function keyword, followed
by name of function and ()
 Statements enclosed in a single pair of
braces {}
16HTML5 and CSS3 – Illustrated, 2nd
Edition
Create a Function
(continued)
Function call: reference to a function
name elsewhere in code to indicate
when function should be executed
Creating and calling a function:
17HTML5 and CSS3 – Illustrated, 2nd
Edition
Add an Event Listener
Events: actions commonly performed
on a web page
 Can write JavaScript that responds to
events
Commonly used events:
18HTML5 and CSS3 – Illustrated, 2nd
Edition
Add an Event Listener
(continued)
Event listener: a statement that
specifies an object, an event, and
function to call in response to event
19HTML5 and CSS3 – Illustrated, 2nd
Edition
Change CSS with JavaScript
Can use JavaScript to change
element's CSS in response to event
 Create style rule using class selector,
then use JavaScript to add/remove class
values from element based on events:
20HTML5 and CSS3 – Illustrated, 2nd
Edition
Create an if Statement
operators: symbols to compare or
change values of multiple objects or
properties
 assignment operator (=)
 comparison operators: determine
whether 2 values same or different
if statement: compares 2 values; if
result is true, statements are executed
21HTML5 and CSS3 – Illustrated, 2nd
Edition
Create an if Statement
(continued)
Syntax for creating an if statement:
Operators:
22HTML5 and CSS3 – Illustrated, 2nd
Edition
Summary
DOM is a standardized way of
referring to parts of a web page
The querySelector() method lets
you reference objects and properties
Script code is created by combining
DOM objects, properties, and
methods
A statement is a JavaScript instruction
that performs an action
23HTML5 and CSS3 – Illustrated, 2nd
Edition
Summary (continued)
The assignment operator lets you
assign a new property value
Variables are stored values you can
access with a name you specify
A function is a group of one or more
statements with an assigned name
A function must be called for its
statements to be executed
24HTML5 and CSS3 – Illustrated, 2nd
Edition
Summary (continued)
An event listener is a statement that
specifies an object, an event, and
function to call in response to event
You can use JavaScript to change the
CSS for an element in response to an
event
An if statement compares 2 values
and executes statements only if the
comparison result is true
25HTML5 and CSS3 – Illustrated, 2nd
Edition

More Related Content

What's hot

Getting Started with CSS
Getting Started with CSSGetting Started with CSS
Getting Started with CSSNicole Ryan
 
Optimizing a website for search engines
Optimizing a website for search enginesOptimizing a website for search engines
Optimizing a website for search enginesNicole Ryan
 
Working with Video and Audio
Working with Video and AudioWorking with Video and Audio
Working with Video and AudioNicole Ryan
 
Creating and Processing Web Forms
Creating and Processing Web FormsCreating and Processing Web Forms
Creating and Processing Web FormsNicole Ryan
 
Social media and your website
Social media and your websiteSocial media and your website
Social media and your websiteNicole Ryan
 
Crystal report
Crystal reportCrystal report
Crystal reportEverywhere
 
Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Slideshare
 
Introduction To Flex
Introduction To FlexIntroduction To Flex
Introduction To FlexYoss Cohen
 
Presentation on HTML
Presentation on HTML Presentation on HTML
Presentation on HTML tauqeer199
 
Quickstart Microsoft access 2013
Quickstart Microsoft access 2013Quickstart Microsoft access 2013
Quickstart Microsoft access 2013comatsg
 
Content Architecture
Content ArchitectureContent Architecture
Content ArchitectureDara Pressley
 
New Features of HTML 5.1 to Create More Flexible Web Experiences
New Features of HTML 5.1 to Create More Flexible Web ExperiencesNew Features of HTML 5.1 to Create More Flexible Web Experiences
New Features of HTML 5.1 to Create More Flexible Web ExperiencesRasin Bekkevold
 
Syncronizing with outlook
Syncronizing with outlookSyncronizing with outlook
Syncronizing with outlookBiswanath Dey
 
MarcEdit for Illinois Library Association conference 2011
MarcEdit for Illinois Library Association conference 2011MarcEdit for Illinois Library Association conference 2011
MarcEdit for Illinois Library Association conference 2011GailBordenTech
 

What's hot (20)

Getting Started with CSS
Getting Started with CSSGetting Started with CSS
Getting Started with CSS
 
Optimizing a website for search engines
Optimizing a website for search enginesOptimizing a website for search engines
Optimizing a website for search engines
 
Working with Video and Audio
Working with Video and AudioWorking with Video and Audio
Working with Video and Audio
 
Creating and Processing Web Forms
Creating and Processing Web FormsCreating and Processing Web Forms
Creating and Processing Web Forms
 
Social media and your website
Social media and your websiteSocial media and your website
Social media and your website
 
Crystal report
Crystal reportCrystal report
Crystal report
 
C# Crystal Reports
C# Crystal ReportsC# Crystal Reports
C# Crystal Reports
 
Crystal report
Crystal reportCrystal report
Crystal report
 
Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010
 
Introduction To Flex
Introduction To FlexIntroduction To Flex
Introduction To Flex
 
M02 un12 p01
M02 un12 p01M02 un12 p01
M02 un12 p01
 
Presentation on HTML
Presentation on HTML Presentation on HTML
Presentation on HTML
 
Dreamweaver Ch03
Dreamweaver Ch03Dreamweaver Ch03
Dreamweaver Ch03
 
Quickstart Microsoft access 2013
Quickstart Microsoft access 2013Quickstart Microsoft access 2013
Quickstart Microsoft access 2013
 
Content Architecture
Content ArchitectureContent Architecture
Content Architecture
 
New Features of HTML 5.1 to Create More Flexible Web Experiences
New Features of HTML 5.1 to Create More Flexible Web ExperiencesNew Features of HTML 5.1 to Create More Flexible Web Experiences
New Features of HTML 5.1 to Create More Flexible Web Experiences
 
Syncronizing with outlook
Syncronizing with outlookSyncronizing with outlook
Syncronizing with outlook
 
MarcEdit for Illinois Library Association conference 2011
MarcEdit for Illinois Library Association conference 2011MarcEdit for Illinois Library Association conference 2011
MarcEdit for Illinois Library Association conference 2011
 
Css 2010
Css 2010Css 2010
Css 2010
 
Cis245 finalreview
Cis245 finalreviewCis245 finalreview
Cis245 finalreview
 

Similar to Javascript programming using the document object model

12. session 12 java script objects
12. session 12   java script objects12. session 12   java script objects
12. session 12 java script objectsPhúc Đỗ
 
INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGProf Ansari
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Jonas Follesø
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Flex Daily Solutions @ FITC 2008
Flex Daily Solutions @ FITC 2008Flex Daily Solutions @ FITC 2008
Flex Daily Solutions @ FITC 2008marcocasario
 
Overview of atg framework
Overview of atg frameworkOverview of atg framework
Overview of atg frameworkYousuf Roushan
 
Ajax toolkit framework
Ajax toolkit frameworkAjax toolkit framework
Ajax toolkit frameworkSunil Kumar
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPAli Shah
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTAAFREEN SHAIKH
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010vchircu
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptxMuqaddarNiazi1
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05Terry Yoast
 

Similar to Javascript programming using the document object model (20)

12. session 12 java script objects
12. session 12   java script objects12. session 12   java script objects
12. session 12 java script objects
 
INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMING
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Lect35 javascript
Lect35 javascriptLect35 javascript
Lect35 javascript
 
Ddpz2613 topic9 java
Ddpz2613 topic9 javaDdpz2613 topic9 java
Ddpz2613 topic9 java
 
Flex Daily Solutions @ FITC 2008
Flex Daily Solutions @ FITC 2008Flex Daily Solutions @ FITC 2008
Flex Daily Solutions @ FITC 2008
 
Overview of atg framework
Overview of atg frameworkOverview of atg framework
Overview of atg framework
 
Ajax toolkit framework
Ajax toolkit frameworkAjax toolkit framework
Ajax toolkit framework
 
JavaScript
JavaScriptJavaScript
JavaScript
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
 
Tutorial Solution
Tutorial SolutionTutorial Solution
Tutorial Solution
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
 
ajax_pdf
ajax_pdfajax_pdf
ajax_pdf
 
ajax_pdf
ajax_pdfajax_pdf
ajax_pdf
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptx
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
Test
TestTest
Test
 
Asp objects
Asp objectsAsp objects
Asp objects
 

More from Nicole Ryan

Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and SetsNicole Ryan
 
Organizing Content with Lists and Tables
Organizing Content with Lists and TablesOrganizing Content with Lists and Tables
Organizing Content with Lists and TablesNicole Ryan
 
Chapter 12 Lecture: GUI Programming, Multithreading, and Animation
Chapter 12 Lecture: GUI Programming, Multithreading, and AnimationChapter 12 Lecture: GUI Programming, Multithreading, and Animation
Chapter 12 Lecture: GUI Programming, Multithreading, and AnimationNicole Ryan
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Nicole Ryan
 
Intro to Programming: Modularity
Intro to Programming: ModularityIntro to Programming: Modularity
Intro to Programming: ModularityNicole Ryan
 
Programming Logic and Design: Arrays
Programming Logic and Design: ArraysProgramming Logic and Design: Arrays
Programming Logic and Design: ArraysNicole Ryan
 
Programming Logic and Design: Working with Data
Programming Logic and Design: Working with DataProgramming Logic and Design: Working with Data
Programming Logic and Design: Working with DataNicole Ryan
 
Setting up your development environment
Setting up your development environmentSetting up your development environment
Setting up your development environmentNicole Ryan
 
Dynamic vs static
Dynamic vs staticDynamic vs static
Dynamic vs staticNicole Ryan
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQLNicole Ryan
 
Using arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationUsing arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationNicole Ryan
 
Tables and forms accessibility and microformats
Tables and forms accessibility and microformatsTables and forms accessibility and microformats
Tables and forms accessibility and microformatsNicole Ryan
 
Creating and styling forms
Creating and styling formsCreating and styling forms
Creating and styling formsNicole Ryan
 
Creating and styling tables
Creating and styling tablesCreating and styling tables
Creating and styling tablesNicole Ryan
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHPNicole Ryan
 
Handling User Input and Processing Form Data
Handling User Input and Processing Form DataHandling User Input and Processing Form Data
Handling User Input and Processing Form DataNicole Ryan
 

More from Nicole Ryan (17)

Inheritance
InheritanceInheritance
Inheritance
 
Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and Sets
 
Organizing Content with Lists and Tables
Organizing Content with Lists and TablesOrganizing Content with Lists and Tables
Organizing Content with Lists and Tables
 
Chapter 12 Lecture: GUI Programming, Multithreading, and Animation
Chapter 12 Lecture: GUI Programming, Multithreading, and AnimationChapter 12 Lecture: GUI Programming, Multithreading, and Animation
Chapter 12 Lecture: GUI Programming, Multithreading, and Animation
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2
 
Intro to Programming: Modularity
Intro to Programming: ModularityIntro to Programming: Modularity
Intro to Programming: Modularity
 
Programming Logic and Design: Arrays
Programming Logic and Design: ArraysProgramming Logic and Design: Arrays
Programming Logic and Design: Arrays
 
Programming Logic and Design: Working with Data
Programming Logic and Design: Working with DataProgramming Logic and Design: Working with Data
Programming Logic and Design: Working with Data
 
Setting up your development environment
Setting up your development environmentSetting up your development environment
Setting up your development environment
 
Dynamic vs static
Dynamic vs staticDynamic vs static
Dynamic vs static
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
 
Using arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationUsing arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing information
 
Tables and forms accessibility and microformats
Tables and forms accessibility and microformatsTables and forms accessibility and microformats
Tables and forms accessibility and microformats
 
Creating and styling forms
Creating and styling formsCreating and styling forms
Creating and styling forms
 
Creating and styling tables
Creating and styling tablesCreating and styling tables
Creating and styling tables
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHP
 
Handling User Input and Processing Form Data
Handling User Input and Processing Form DataHandling User Input and Processing Form Data
Handling User Input and Processing Form Data
 

Recently uploaded

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 

Javascript programming using the document object model

  • 1. Programming Web Pages with JavaScript
  • 2. Objectives Explore the Document Object Model Access elements and properties using JavaScript Create statements Store and access data in variables 2HTML5 and CSS3 – Illustrated, 2nd Edition
  • 3. Objectives (continued) Create a function Add an event listener Change CSS with JavaScript Create an if statement 3HTML5 and CSS3 – Illustrated, 2nd Edition
  • 4. Explore the Document Object Model JavaScript: the most widely used programming language for modern web browsers Document Object Model (DOM): standardized way of referring to parts of a web page  Creates a hierarchical arrangement known as a DOM tree  Each part of HTML document represented by a node 4HTML5 and CSS3 – Illustrated, 2nd Edition
  • 5. Explore the Document Object Model (continued) Object: HTML element in DOM  Specific object must be identified in order to manipulate it using JavaScript Property: piece of a standard set of information associated with DOM node  Attributes are considered their own nodes and are associated with their own properties 5HTML5 and CSS3 – Illustrated, 2nd Edition
  • 6. Explore the Document Object Model (continued) Method: action that can be performed for a node  Method names are followed by parentheses between which you specify information specific to the method  querySelector() method lets you access any HTML element by specifying a CSS selector • Example: querySelector("#nameinput") selects the element with the id value nameinput 6HTML5 and CSS3 – Illustrated, 2nd Edition
  • 7. Explore the Document Object Model (continued) A DOM Tree 7HTML5 and CSS3 – Illustrated, 2nd Edition
  • 8. Access Elements and Properties Using JavaScript querySelector() method lets you reference objects and properties  querySelector() is a child of the Document object To use a method, specify its parent object, a period, and method name: document.querySelector() 8HTML5 and CSS3 – Illustrated, 2nd Edition
  • 9. Access Elements and Properties Using JavaScript (continued) Specify CSS selector within parentheses of method to reference an object  To select the aside element: document.querySelector("aside") To access a property, add dot and property name after method: document.querySelector("aside").textContent 9HTML5 and CSS3 – Illustrated, 2nd Edition
  • 10. Access Elements and Properties Using JavaScript (continued) Console: part of developer tools in modern browsers; can be used to enter test code and view error messages related to JavaScript The browser console in Chrome: 10HTML5 and CSS3 – Illustrated, 2nd Edition
  • 11. Create Statements Statement: a JavaScript instruction that performs an action: Assignment operator (=): Part of a statement that lets you assign a new property value  Code on left of = accesses property  Code on right of = specifies new value • often enclosed in quotes 11HTML5 and CSS3 – Illustrated, 2nd Edition
  • 12. Create Statements (continued) Every JavaScript statement ends with a semicolon (;) Statements created in external JavaScript file  Text file with .js extension  Referenced within HTML document using script element 12HTML5 and CSS3 – Illustrated, 2nd Edition
  • 13. Create Statements (continued) Statements added to file: script element in HTML document: 13HTML5 and CSS3 – Illustrated, 2nd Edition
  • 14. Store and Access Data in Variables Variables: Stored values you can access with a name you specify  Can store many types of information  Create with var keyword followed by name, equal sign, and value: 14HTML5 and CSS3 – Illustrated, 2nd Edition
  • 15. Store and Access Data in Variables (continued) Shorter statements easier to work with  Common to store object references as variables, then reference in other statements using variable names: 15HTML5 and CSS3 – Illustrated, 2nd Edition
  • 16. Create a Function Function: Group of one or more statements with an assigned name  Statements in function referenced as a single unit  Create with function keyword, followed by name of function and ()  Statements enclosed in a single pair of braces {} 16HTML5 and CSS3 – Illustrated, 2nd Edition
  • 17. Create a Function (continued) Function call: reference to a function name elsewhere in code to indicate when function should be executed Creating and calling a function: 17HTML5 and CSS3 – Illustrated, 2nd Edition
  • 18. Add an Event Listener Events: actions commonly performed on a web page  Can write JavaScript that responds to events Commonly used events: 18HTML5 and CSS3 – Illustrated, 2nd Edition
  • 19. Add an Event Listener (continued) Event listener: a statement that specifies an object, an event, and function to call in response to event 19HTML5 and CSS3 – Illustrated, 2nd Edition
  • 20. Change CSS with JavaScript Can use JavaScript to change element's CSS in response to event  Create style rule using class selector, then use JavaScript to add/remove class values from element based on events: 20HTML5 and CSS3 – Illustrated, 2nd Edition
  • 21. Create an if Statement operators: symbols to compare or change values of multiple objects or properties  assignment operator (=)  comparison operators: determine whether 2 values same or different if statement: compares 2 values; if result is true, statements are executed 21HTML5 and CSS3 – Illustrated, 2nd Edition
  • 22. Create an if Statement (continued) Syntax for creating an if statement: Operators: 22HTML5 and CSS3 – Illustrated, 2nd Edition
  • 23. Summary DOM is a standardized way of referring to parts of a web page The querySelector() method lets you reference objects and properties Script code is created by combining DOM objects, properties, and methods A statement is a JavaScript instruction that performs an action 23HTML5 and CSS3 – Illustrated, 2nd Edition
  • 24. Summary (continued) The assignment operator lets you assign a new property value Variables are stored values you can access with a name you specify A function is a group of one or more statements with an assigned name A function must be called for its statements to be executed 24HTML5 and CSS3 – Illustrated, 2nd Edition
  • 25. Summary (continued) An event listener is a statement that specifies an object, an event, and function to call in response to event You can use JavaScript to change the CSS for an element in response to an event An if statement compares 2 values and executes statements only if the comparison result is true 25HTML5 and CSS3 – Illustrated, 2nd Edition