SlideShare a Scribd company logo
1 of 79
Download to read offline
Getting Started with DOM
writing HTML documents 
1. you encapsulate HTML inside other HTML 
2. you set up a hierarchy 
3. it is indicated visually by indenting 
4. it can be expressed as a tree
browser’s job 
1. when loads the HTML interrupts the process 
2. to simulate the markup encapsulation 
3. parsing this hierarchy to create a tree of objects
Contents 
1. Node Types 
2. Interfaces 
3. Inheritance 
4. Element Node 
5. Text Node 
6. Events 
7. Document Fragment
1.Node Type 
9 
1 
2 
3 
11 
10 
document.DOCUMENT_NODE 
document.ELEMENT_NODE 
document.ATTRIBUTE_NODE 
document.TEXT_NODE 
document.DOCUMENT_FRAGMENT_NODE 
document.DOCUMENT_TYPE_NODE
1. Node Type 
document.DOCUMENT_NODE === 9 
<!doctype html>! 
<html>! 
!<head>! 
!! <tittle></tittle>! 
!</head>! 
!<body class=“widget”>! 
!! Hello World!! 
!</body>! 
</html>
1. Node Type 
document.DOCUMENT_NODE === 9 
document
1. Node Type 
document.ELEMENT_NODE === 1 
<!doctype html>! 
<html>! 
!<head>! 
!! <tittle></tittle>! 
!</head>! 
!<body class=“widget”>! 
!! Hello World!! 
!</body>! 
</html>
1. Node Type 
document.ELEMENT_NODE === 1 
document.body
1. Node Type 
document.ATTRIBUTE_NODE === 2 
<!doctype html>! 
<html>! 
!<head>! 
!! <tittle></tittle>! 
!</head>! 
!<body class=“widget”>! 
!! Hello World!! 
!</body>! 
</html>
1. Node Type 
document.ATTRIBUTE_NODE === 2 
document.createAttribute(‘class’);
1. Node Type 
document.TEXT_NODE === 3 
<!doctype html>! 
<html>! 
!<head>! 
!! <tittle></tittle>! 
!</head>! 
!<body class=“widget”>! 
!! Hello World!! 
!</body>! 
</html>
1. Node Type 
document.TEXT_NODE === 3 
document.createTextNode(‘Hello World!’);
1. Node Type 
document.DOCUMENT_TYPE_NODE === 10 
<!doctype html>! 
<html>! 
!<head>! 
!! <tittle></tittle>! 
!</head>! 
!<body class=“widget”>! 
!! Hello World!! 
!</body>! 
</html>
1. Node Type 
document.DOCUMENT_TYPE_NODE === 10 
document.doctype
1. Node Type 
document.DOCUMENT_FRAGMENT_NODE === 11 
<!doctype html>! 
<html>! 
!<head>! 
!! <tittle></tittle>! 
!</head>! 
!<body class=“widget”>! 
!! Hello World!! 
!</body>! 
</html>
1. Node Type 
document.DOCUMENT_FRAGMENT_NODE === 11 
document.createDocumentFragment()
2. Interfaces
2. Interfaces 
p instanceof HTMLParagraphElement 
HTMLHtmlElement! 
HTMLHeadElement! 
HTMLLinkElement! 
HTMLTitleElement! 
HTMLStyleElement! 
HTMLBodyElement! 
HTMLFormElement
3. Inheritance
3. Inheritance 
document 
Node 
HTMLElement
4. Element Node
4. Element Node 
Node properties 
dataset! 
attributes! 
tagName! 
children
4. Element Node 
Node methods 
createElement()! 
getAttribute()! 
setAttribute()! 
hasAttribute()! 
removeAttribute()! 
classList()
4. Element Node 
Working with string 
innerHTML! 
innerText! 
outerHTML! 
textContent! 
insertAdjacentHTML()
4. Element Node 
Working with nodes 
appendChild()! 
removeChild()! 
replaceChild()! 
insertBefore()! 
cloneNode()
4. Element Node 
Node selection 
single element 
multiple elements 
preconfigured 
collections
4. Element Node 
Node selection 
single element 
multiple elements 
preconfigured 
collections 
querySelector()! 
getElementById()
4. Element Node 
Node selection 
single element 
multiple elements 
preconfigured 
collections 
querySelector()! 
getElementById() 
querySelectorAll()! 
getElementsByTagName()! 
getElementsByClassName()
4. Element Node 
Node selection 
single element 
multiple elements 
preconfigured 
collections 
querySelector()! 
getElementById() 
querySelectorAll()! 
getElementsByTagName()! 
getElementsByClassName() 
document.all! 
document.forms! 
document.links! 
document.images
4. Element Node 
Collections types 
Live 
Static
4. Element Node 
Collection type: Live 
Live 
Static 
getElementsByTagName()! 
getElementsByClassName()! 
document.all! 
document.links! 
document.images! 
querySelector().childNodes! 
!
4. Element Node 
Collection type: Static 
Live 
Static 
getElementsByTagName()! 
getElementsByClassName()! 
document.all! 
document.links! 
document.images! 
querySelector().childNodes! 
! 
querySelectorAll()
4. Element Node 
Collections types 
HTMLCollection 
NodeList 
StyleSheetList 
querySelector().children! 
! 
querySelector().childNodes! 
! 
document.styleSheets
4. Element Node 
Width without borders 
querySelector().clientWidth
4. Element Node 
Width with borders 
querySelector().getBoudingClientRect().width
4. Element Node 
First parent positioned 
querySelector().offsetParent
4. Element Node 
Top to the offsetParent 
querySelector().offsetTop
4. Element Node 
Left to the offsetParent 
querySelector().offsetLeft
4. Element Node 
Real height 
querySelector().scrollHeight
4. Element Node 
Scrolled top difference 
querySelector().scrollTop
4. Element Node 
Real width 
querySelector().scrollWidth
4. Element Node 
Scrolled left difference 
querySelector().scrollLeft
5. Text Node
5. Text Node 
Node properties 
data! 
textContent! 
nodeValue
splitText()! 
normalize()! 
appendData(‘!’)! 
deleteData(3,5)! 
insertData(2,’Text’)! 
replaceData(1,2,’Text’)! 
substringData(2,3) 
5. Text Node 
Node methods
5. Text Node 
Text nodes 
<p>This is <code>TEXT_NODE</code>.</p>
6. Events 
It is a predefined or a custom moment in time that 
occurs in relationship to an element in the DOM, de 
document object or the window object.
6. Events 
Setting Events 
1. Inline Event Handler 
2. Property Event Handler 
3. addEventListener() method
DOM Event Types 
Event! 
UIEvent! 
MouseEvent! 
FocusEvent! 
WheelEvent! 
TouchEvent! 
HashChangeEvent! 
NavigatorOnLine! 
PageTransitionEvent! 
DragEvent 
6. Events
6. Events 
Event type 
readystatechange! 
DOMContentLoaded
6. Events 
UIEvent type 
load! 
abort! 
unload! 
error! 
resize! 
scroll
MouseEvent type 
contextMenu! 
click! 
dbclick! 
mousedown! 
mouseenter! 
mouseleave! 
mousemove! 
mouseout! 
mouseup! 
mouseover 
6. Events
6. Events 
FocusEvent type 
blur! 
focus! 
focusin! 
focusout
6. Events 
Form Events type 
change! 
reset! 
submit! 
select
6. Events 
WheelEvent type 
wheel/mousewheel
6. Events 
KeyboardEvent type 
keydown! 
keypress! 
keyup
6. Events 
TouchEvent type 
touchstart! 
touchend! 
touchmove! 
touchenter! 
touchleave! 
touchcancel
6. Events 
HashChangeEvent type 
hashchange
6. Events 
NavigatorOnLine type 
online! 
offline
6. Events 
PageTransitionEvent type 
pagehide! 
pageshow
DragEvent type 
drag! 
dragstart! 
dragend! 
dragenter! 
dragleave! 
dragover! 
drop 
6. Events
6. Events 
The Event Flow 
is composed by two phases 
! 
1. Capture Event Phase 
2. Propagation/Bubbling Event Phase
6. Events 
Capture Event Phase
6. Events 
Capture Event Phase 
window.addEventListener(…,…,true) 
document.addEventListener(…,…,true) 
document.body.addEventListener(…,…,true) 
document.querySelector(‘div’).addEventListener(…,…,true)
6. Events 
Capture Event Phase
6. Events 
Capture Event Phase 
window.addEventListener(…,…,true)
6. Events 
Capture Event Phase 
window.addEventListener(…,…,true) 
document.addEventListener(…,…,true)
6. Events 
Capture Event Phase 
window.addEventListener(…,…,true) 
document.addEventListener(…,…,true) 
document.body.addEventListener(…,…,true)
6. Events 
Capture Event Phase 
window.addEventListener(…,…,true) 
document.addEventListener(…,…,true) 
document.body.addEventListener(…,…,true) 
document.querySelector(‘div’).addEventListener(…,…,true)
6. Events 
Propagation Event Phase
6. Events 
Propagation Event Phase 
document.querySelector(‘div’).addEventListener(…,…,false) 
document.body.addEventListener(…,…,false) 
document.addEventListener(…,…,false) 
window.addEventListener(…,…,false)
6. Events 
Propagation Event Phase 
document.querySelector(‘div’).addEventListener(…,…,false)
6. Events 
Propagation Event Phase 
document.querySelector(‘div’).addEventListener(…,…,false) 
document.body.addEventListener(…,…,false)
6. Events 
Propagation Event Phase 
document.querySelector(‘div’).addEventListener(…,…,false) 
document.body.addEventListener(…,…,false) 
document.addEventListener(…,…,false)
6. Events 
Propagation Event Phase 
document.querySelector(‘div’).addEventListener(…,…,false) 
document.body.addEventListener(…,…,false) 
document.addEventListener(…,…,false) 
window.addEventListener(…,…,false)
7. Document Fragment 
It is a empty document template 
It acts just like the live DOM tree 
It only lives in memory 
It can’t contain <body> and <html> node 
It’s not added to the DOM when a fragment is 
appended
7. Document Fragment 
innerHTML hack 
var div = document.createElement(‘div’);! 
var frag = document.createDocumentFragment();! 
div.innerHTML = ‘<p>It is <strong>better</strong>.</p>’;! 
! 
frag.appendChild(div);! 
document.body.appendChild(frag);
The end!

More Related Content

What's hot

ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)Clément Wehrung
 
Simplifying CSS Selectors
Simplifying CSS SelectorsSimplifying CSS Selectors
Simplifying CSS SelectorsBaris Aydinoglu
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulationborkweb
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2borkweb
 
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...Nicole Sullivan
 
KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7phuphax
 
CSC103 Web Technologies: HTML, CSS, JS
CSC103 Web Technologies: HTML, CSS, JSCSC103 Web Technologies: HTML, CSS, JS
CSC103 Web Technologies: HTML, CSS, JSRichard Homa
 
Html,javascript & css
Html,javascript & cssHtml,javascript & css
Html,javascript & cssPredhin Sapru
 
Introduction to HTML, CSS, and Javascript
Introduction to HTML, CSS, and JavascriptIntroduction to HTML, CSS, and Javascript
Introduction to HTML, CSS, and JavascriptAgustinus Theodorus
 
JavaScript Workshop
JavaScript WorkshopJavaScript Workshop
JavaScript WorkshopPamela Fox
 
Introduction to HTML5 and CSS3 (revised)
Introduction to HTML5 and CSS3 (revised)Introduction to HTML5 and CSS3 (revised)
Introduction to HTML5 and CSS3 (revised)Joseph Lewis
 
A quick guide to Css and java script
A quick guide to Css and  java scriptA quick guide to Css and  java script
A quick guide to Css and java scriptAVINASH KUMAR
 
Interacting with the DOM (JavaScript)
Interacting with the DOM (JavaScript)Interacting with the DOM (JavaScript)
Interacting with the DOM (JavaScript)Florence Davis
 
Intro to html5 Boilerplate
Intro to html5 BoilerplateIntro to html5 Boilerplate
Intro to html5 BoilerplateMichael Enslow
 

What's hot (20)

ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
 
Simplifying CSS Selectors
Simplifying CSS SelectorsSimplifying CSS Selectors
Simplifying CSS Selectors
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
 
KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7
 
CSC103 Web Technologies: HTML, CSS, JS
CSC103 Web Technologies: HTML, CSS, JSCSC103 Web Technologies: HTML, CSS, JS
CSC103 Web Technologies: HTML, CSS, JS
 
Html,javascript & css
Html,javascript & cssHtml,javascript & css
Html,javascript & css
 
Introduction to HTML, CSS, and Javascript
Introduction to HTML, CSS, and JavascriptIntroduction to HTML, CSS, and Javascript
Introduction to HTML, CSS, and Javascript
 
JavaScript Workshop
JavaScript WorkshopJavaScript Workshop
JavaScript Workshop
 
CSS3 and Selectors
CSS3 and SelectorsCSS3 and Selectors
CSS3 and Selectors
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
Introduction to HTML5 and CSS3 (revised)
Introduction to HTML5 and CSS3 (revised)Introduction to HTML5 and CSS3 (revised)
Introduction to HTML5 and CSS3 (revised)
 
Looking into HTML5
Looking into HTML5Looking into HTML5
Looking into HTML5
 
A quick guide to Css and java script
A quick guide to Css and  java scriptA quick guide to Css and  java script
A quick guide to Css and java script
 
Interacting with the DOM (JavaScript)
Interacting with the DOM (JavaScript)Interacting with the DOM (JavaScript)
Interacting with the DOM (JavaScript)
 
Chapter6
Chapter6Chapter6
Chapter6
 
Intro to html5 Boilerplate
Intro to html5 BoilerplateIntro to html5 Boilerplate
Intro to html5 Boilerplate
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 

Viewers also liked

The prototype property
The prototype propertyThe prototype property
The prototype propertyHernan Mammana
 
Ee2 chapter13 counters
Ee2 chapter13 countersEe2 chapter13 counters
Ee2 chapter13 countersCK Yang
 
Ee2 chapter14 ic_counters
Ee2 chapter14 ic_countersEe2 chapter14 ic_counters
Ee2 chapter14 ic_countersCK Yang
 
HTML5 - Just the basics
HTML5 - Just the basicsHTML5 - Just the basics
HTML5 - Just the basicsJames VanDyke
 
JavaScript regular expression
JavaScript regular expressionJavaScript regular expression
JavaScript regular expressionHernan Mammana
 
Web topic 1 internet
Web topic 1  internetWeb topic 1  internet
Web topic 1 internetCK Yang
 
Preparing images for the Web
Preparing images for the WebPreparing images for the Web
Preparing images for the Websdireland
 
Web topic 27 class test
Web topic 27  class testWeb topic 27  class test
Web topic 27 class testCK Yang
 
Web topic 31 setup remote site
Web topic 31  setup remote siteWeb topic 31  setup remote site
Web topic 31 setup remote siteCK Yang
 
Web topic 33 publish websites
Web topic 33  publish websitesWeb topic 33  publish websites
Web topic 33 publish websitesCK Yang
 
Web topic 11 importance of html validation
Web topic 11  importance of html validationWeb topic 11  importance of html validation
Web topic 11 importance of html validationCK Yang
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101Raj Rajandran
 

Viewers also liked (16)

Tipowebgrafía
TipowebgrafíaTipowebgrafía
Tipowebgrafía
 
The prototype property
The prototype propertyThe prototype property
The prototype property
 
Ee2 chapter13 counters
Ee2 chapter13 countersEe2 chapter13 counters
Ee2 chapter13 counters
 
Layout
LayoutLayout
Layout
 
The html5 outline
The html5 outlineThe html5 outline
The html5 outline
 
Ee2 chapter14 ic_counters
Ee2 chapter14 ic_countersEe2 chapter14 ic_counters
Ee2 chapter14 ic_counters
 
Live streaming
Live streamingLive streaming
Live streaming
 
HTML5 - Just the basics
HTML5 - Just the basicsHTML5 - Just the basics
HTML5 - Just the basics
 
JavaScript regular expression
JavaScript regular expressionJavaScript regular expression
JavaScript regular expression
 
Web topic 1 internet
Web topic 1  internetWeb topic 1  internet
Web topic 1 internet
 
Preparing images for the Web
Preparing images for the WebPreparing images for the Web
Preparing images for the Web
 
Web topic 27 class test
Web topic 27  class testWeb topic 27  class test
Web topic 27 class test
 
Web topic 31 setup remote site
Web topic 31  setup remote siteWeb topic 31  setup remote site
Web topic 31 setup remote site
 
Web topic 33 publish websites
Web topic 33  publish websitesWeb topic 33  publish websites
Web topic 33 publish websites
 
Web topic 11 importance of html validation
Web topic 11  importance of html validationWeb topic 11  importance of html validation
Web topic 11 importance of html validation
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
 

Similar to Getting Started with DOM

Zotero Framework Translators
Zotero Framework TranslatorsZotero Framework Translators
Zotero Framework Translatorsadam3smith
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksHjörtur Hilmarsson
 
Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014Naresha K
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It TodayDoris Chen
 
Practical JavaScript Programming - Session 4/8
Practical JavaScript Programming - Session 4/8Practical JavaScript Programming - Session 4/8
Practical JavaScript Programming - Session 4/8Wilson Su
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom eventBunlong Van
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...SPTechCon
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)Nicholas Zakas
 
The Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQueryThe Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQuerycolinbdclark
 
Ingo Muschenetz: Titanium Studio Deep Dive
Ingo Muschenetz: Titanium Studio Deep DiveIngo Muschenetz: Titanium Studio Deep Dive
Ingo Muschenetz: Titanium Studio Deep DiveAxway Appcelerator
 
Summit2014 topic 0066 - 10 enhancements that require 10 lines of code
Summit2014 topic 0066 - 10 enhancements that require 10 lines of codeSummit2014 topic 0066 - 10 enhancements that require 10 lines of code
Summit2014 topic 0066 - 10 enhancements that require 10 lines of codeAngel Borroy López
 
Document Object Model
Document Object ModelDocument Object Model
Document Object ModelMayur Mudgal
 
The go-start webframework (GTUG Vienna 27.03.2012)
The go-start webframework (GTUG Vienna 27.03.2012)The go-start webframework (GTUG Vienna 27.03.2012)
The go-start webframework (GTUG Vienna 27.03.2012)ungerik
 

Similar to Getting Started with DOM (20)

Zotero Framework Translators
Zotero Framework TranslatorsZotero Framework Translators
Zotero Framework Translators
 
68837.ppt
68837.ppt68837.ppt
68837.ppt
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
 
Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
 
Practical JavaScript Programming - Session 4/8
Practical JavaScript Programming - Session 4/8Practical JavaScript Programming - Session 4/8
Practical JavaScript Programming - Session 4/8
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom event
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)
 
Javascript projects Course
Javascript projects CourseJavascript projects Course
Javascript projects Course
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
The Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQueryThe Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQuery
 
Scripting The Dom
Scripting The DomScripting The Dom
Scripting The Dom
 
Ingo Muschenetz: Titanium Studio Deep Dive
Ingo Muschenetz: Titanium Studio Deep DiveIngo Muschenetz: Titanium Studio Deep Dive
Ingo Muschenetz: Titanium Studio Deep Dive
 
Summit2014 topic 0066 - 10 enhancements that require 10 lines of code
Summit2014 topic 0066 - 10 enhancements that require 10 lines of codeSummit2014 topic 0066 - 10 enhancements that require 10 lines of code
Summit2014 topic 0066 - 10 enhancements that require 10 lines of code
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
lect9
lect9lect9
lect9
 
lect9
lect9lect9
lect9
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
The go-start webframework (GTUG Vienna 27.03.2012)
The go-start webframework (GTUG Vienna 27.03.2012)The go-start webframework (GTUG Vienna 27.03.2012)
The go-start webframework (GTUG Vienna 27.03.2012)
 

Recently uploaded

AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxNadaHaitham1
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 

Recently uploaded (20)

AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 

Getting Started with DOM

  • 2. writing HTML documents 1. you encapsulate HTML inside other HTML 2. you set up a hierarchy 3. it is indicated visually by indenting 4. it can be expressed as a tree
  • 3. browser’s job 1. when loads the HTML interrupts the process 2. to simulate the markup encapsulation 3. parsing this hierarchy to create a tree of objects
  • 4. Contents 1. Node Types 2. Interfaces 3. Inheritance 4. Element Node 5. Text Node 6. Events 7. Document Fragment
  • 5. 1.Node Type 9 1 2 3 11 10 document.DOCUMENT_NODE document.ELEMENT_NODE document.ATTRIBUTE_NODE document.TEXT_NODE document.DOCUMENT_FRAGMENT_NODE document.DOCUMENT_TYPE_NODE
  • 6. 1. Node Type document.DOCUMENT_NODE === 9 <!doctype html>! <html>! !<head>! !! <tittle></tittle>! !</head>! !<body class=“widget”>! !! Hello World!! !</body>! </html>
  • 7. 1. Node Type document.DOCUMENT_NODE === 9 document
  • 8. 1. Node Type document.ELEMENT_NODE === 1 <!doctype html>! <html>! !<head>! !! <tittle></tittle>! !</head>! !<body class=“widget”>! !! Hello World!! !</body>! </html>
  • 9. 1. Node Type document.ELEMENT_NODE === 1 document.body
  • 10. 1. Node Type document.ATTRIBUTE_NODE === 2 <!doctype html>! <html>! !<head>! !! <tittle></tittle>! !</head>! !<body class=“widget”>! !! Hello World!! !</body>! </html>
  • 11. 1. Node Type document.ATTRIBUTE_NODE === 2 document.createAttribute(‘class’);
  • 12. 1. Node Type document.TEXT_NODE === 3 <!doctype html>! <html>! !<head>! !! <tittle></tittle>! !</head>! !<body class=“widget”>! !! Hello World!! !</body>! </html>
  • 13. 1. Node Type document.TEXT_NODE === 3 document.createTextNode(‘Hello World!’);
  • 14. 1. Node Type document.DOCUMENT_TYPE_NODE === 10 <!doctype html>! <html>! !<head>! !! <tittle></tittle>! !</head>! !<body class=“widget”>! !! Hello World!! !</body>! </html>
  • 15. 1. Node Type document.DOCUMENT_TYPE_NODE === 10 document.doctype
  • 16. 1. Node Type document.DOCUMENT_FRAGMENT_NODE === 11 <!doctype html>! <html>! !<head>! !! <tittle></tittle>! !</head>! !<body class=“widget”>! !! Hello World!! !</body>! </html>
  • 17. 1. Node Type document.DOCUMENT_FRAGMENT_NODE === 11 document.createDocumentFragment()
  • 19. 2. Interfaces p instanceof HTMLParagraphElement HTMLHtmlElement! HTMLHeadElement! HTMLLinkElement! HTMLTitleElement! HTMLStyleElement! HTMLBodyElement! HTMLFormElement
  • 21. 3. Inheritance document Node HTMLElement
  • 23. 4. Element Node Node properties dataset! attributes! tagName! children
  • 24. 4. Element Node Node methods createElement()! getAttribute()! setAttribute()! hasAttribute()! removeAttribute()! classList()
  • 25. 4. Element Node Working with string innerHTML! innerText! outerHTML! textContent! insertAdjacentHTML()
  • 26. 4. Element Node Working with nodes appendChild()! removeChild()! replaceChild()! insertBefore()! cloneNode()
  • 27. 4. Element Node Node selection single element multiple elements preconfigured collections
  • 28. 4. Element Node Node selection single element multiple elements preconfigured collections querySelector()! getElementById()
  • 29. 4. Element Node Node selection single element multiple elements preconfigured collections querySelector()! getElementById() querySelectorAll()! getElementsByTagName()! getElementsByClassName()
  • 30. 4. Element Node Node selection single element multiple elements preconfigured collections querySelector()! getElementById() querySelectorAll()! getElementsByTagName()! getElementsByClassName() document.all! document.forms! document.links! document.images
  • 31. 4. Element Node Collections types Live Static
  • 32. 4. Element Node Collection type: Live Live Static getElementsByTagName()! getElementsByClassName()! document.all! document.links! document.images! querySelector().childNodes! !
  • 33. 4. Element Node Collection type: Static Live Static getElementsByTagName()! getElementsByClassName()! document.all! document.links! document.images! querySelector().childNodes! ! querySelectorAll()
  • 34. 4. Element Node Collections types HTMLCollection NodeList StyleSheetList querySelector().children! ! querySelector().childNodes! ! document.styleSheets
  • 35. 4. Element Node Width without borders querySelector().clientWidth
  • 36. 4. Element Node Width with borders querySelector().getBoudingClientRect().width
  • 37. 4. Element Node First parent positioned querySelector().offsetParent
  • 38. 4. Element Node Top to the offsetParent querySelector().offsetTop
  • 39. 4. Element Node Left to the offsetParent querySelector().offsetLeft
  • 40. 4. Element Node Real height querySelector().scrollHeight
  • 41. 4. Element Node Scrolled top difference querySelector().scrollTop
  • 42. 4. Element Node Real width querySelector().scrollWidth
  • 43. 4. Element Node Scrolled left difference querySelector().scrollLeft
  • 45. 5. Text Node Node properties data! textContent! nodeValue
  • 46. splitText()! normalize()! appendData(‘!’)! deleteData(3,5)! insertData(2,’Text’)! replaceData(1,2,’Text’)! substringData(2,3) 5. Text Node Node methods
  • 47. 5. Text Node Text nodes <p>This is <code>TEXT_NODE</code>.</p>
  • 48. 6. Events It is a predefined or a custom moment in time that occurs in relationship to an element in the DOM, de document object or the window object.
  • 49. 6. Events Setting Events 1. Inline Event Handler 2. Property Event Handler 3. addEventListener() method
  • 50. DOM Event Types Event! UIEvent! MouseEvent! FocusEvent! WheelEvent! TouchEvent! HashChangeEvent! NavigatorOnLine! PageTransitionEvent! DragEvent 6. Events
  • 51. 6. Events Event type readystatechange! DOMContentLoaded
  • 52. 6. Events UIEvent type load! abort! unload! error! resize! scroll
  • 53. MouseEvent type contextMenu! click! dbclick! mousedown! mouseenter! mouseleave! mousemove! mouseout! mouseup! mouseover 6. Events
  • 54. 6. Events FocusEvent type blur! focus! focusin! focusout
  • 55. 6. Events Form Events type change! reset! submit! select
  • 56. 6. Events WheelEvent type wheel/mousewheel
  • 57. 6. Events KeyboardEvent type keydown! keypress! keyup
  • 58. 6. Events TouchEvent type touchstart! touchend! touchmove! touchenter! touchleave! touchcancel
  • 59. 6. Events HashChangeEvent type hashchange
  • 60. 6. Events NavigatorOnLine type online! offline
  • 61. 6. Events PageTransitionEvent type pagehide! pageshow
  • 62. DragEvent type drag! dragstart! dragend! dragenter! dragleave! dragover! drop 6. Events
  • 63. 6. Events The Event Flow is composed by two phases ! 1. Capture Event Phase 2. Propagation/Bubbling Event Phase
  • 64. 6. Events Capture Event Phase
  • 65. 6. Events Capture Event Phase window.addEventListener(…,…,true) document.addEventListener(…,…,true) document.body.addEventListener(…,…,true) document.querySelector(‘div’).addEventListener(…,…,true)
  • 66. 6. Events Capture Event Phase
  • 67. 6. Events Capture Event Phase window.addEventListener(…,…,true)
  • 68. 6. Events Capture Event Phase window.addEventListener(…,…,true) document.addEventListener(…,…,true)
  • 69. 6. Events Capture Event Phase window.addEventListener(…,…,true) document.addEventListener(…,…,true) document.body.addEventListener(…,…,true)
  • 70. 6. Events Capture Event Phase window.addEventListener(…,…,true) document.addEventListener(…,…,true) document.body.addEventListener(…,…,true) document.querySelector(‘div’).addEventListener(…,…,true)
  • 71. 6. Events Propagation Event Phase
  • 72. 6. Events Propagation Event Phase document.querySelector(‘div’).addEventListener(…,…,false) document.body.addEventListener(…,…,false) document.addEventListener(…,…,false) window.addEventListener(…,…,false)
  • 73. 6. Events Propagation Event Phase document.querySelector(‘div’).addEventListener(…,…,false)
  • 74. 6. Events Propagation Event Phase document.querySelector(‘div’).addEventListener(…,…,false) document.body.addEventListener(…,…,false)
  • 75. 6. Events Propagation Event Phase document.querySelector(‘div’).addEventListener(…,…,false) document.body.addEventListener(…,…,false) document.addEventListener(…,…,false)
  • 76. 6. Events Propagation Event Phase document.querySelector(‘div’).addEventListener(…,…,false) document.body.addEventListener(…,…,false) document.addEventListener(…,…,false) window.addEventListener(…,…,false)
  • 77. 7. Document Fragment It is a empty document template It acts just like the live DOM tree It only lives in memory It can’t contain <body> and <html> node It’s not added to the DOM when a fragment is appended
  • 78. 7. Document Fragment innerHTML hack var div = document.createElement(‘div’);! var frag = document.createDocumentFragment();! div.innerHTML = ‘<p>It is <strong>better</strong>.</p>’;! ! frag.appendChild(div);! document.body.appendChild(frag);