Top Banner
Getting Started with DOM
30

Getting Started with DOM - Part 1/3

Aug 19, 2014

Download

Engineering

Hernán Mammana

Talk's slide "Getting Started with DOM" given at MercadoLibre.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting Started with DOM - Part 1/3

Getting Started with DOM

Page 2: Getting Started with DOM - Part 1/3

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

Page 3: Getting Started with DOM - Part 1/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

Page 4: Getting Started with DOM - Part 1/3

NodeNode Type

Interfaces / Constructors

Inheritance

Properties and Methods

Collections type

Traversing

Page 5: Getting Started with DOM - Part 1/3

HTML document<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 6: Getting Started with DOM - Part 1/3

HTML document

document

Page 7: Getting Started with DOM - Part 1/3

DOCUMENT_NODE === 9

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 8: Getting Started with DOM - Part 1/3

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 9: Getting Started with DOM - Part 1/3

ELEMENT_NODE === 1

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 10: Getting Started with DOM - Part 1/3

ELEMENT_NODE === 1

document.body

Page 11: Getting Started with DOM - Part 1/3

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 12: Getting Started with DOM - Part 1/3

ATTRIBUTE_NODE === 2

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 13: Getting Started with DOM - Part 1/3

ATTRIBUTE_NODE === 2

document.createAttribute(‘class’);

Page 14: Getting Started with DOM - Part 1/3

TEXT_NODE === 3

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 15: Getting Started with DOM - Part 1/3

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 16: Getting Started with DOM - Part 1/3

TEXT_NODE === 3

document.createTextNode(‘Hello World!’);

Page 17: Getting Started with DOM - Part 1/3

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 18: Getting Started with DOM - Part 1/3

DOCUMENT_TYPE_NODE === 10

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 19: Getting Started with DOM - Part 1/3

DOCUMENT_TYPE_NODE === 10

document.doctype

Page 20: Getting Started with DOM - Part 1/3

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 21: Getting Started with DOM - Part 1/3

DOCUMENT_FRAGMENT_NODE === 11

<!doctype html> <html> <head> <tittle></tittle> </head> <body class=“widget”> Hello World! </body> </html>

Page 22: Getting Started with DOM - Part 1/3

DOCUMENT_FRAGMENT_NODE === 11

document.createDocumentFragment()

Page 23: Getting Started with DOM - Part 1/3

Node Type9

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

Page 24: Getting Started with DOM - Part 1/3

Interfaces / ConstructorsHTMLHtmlElement

HTMLHeadElement

HTMLLinkElement

HTMLTitleElement

HTMLStyleElement

HTMLBodyElement

HTMLFormElement

Page 25: Getting Started with DOM - Part 1/3

Inheritance

document

Node

HTMLElement

Page 26: Getting Started with DOM - Part 1/3

Propertiesdocument.URL!

document.location!

document.referrer!

document.lastModified!

document.defaultView!

document.plugins

Page 27: Getting Started with DOM - Part 1/3

Propertiesdocument.doctype

document.documentElement

document.head

document.body

document.activeElement

document.title

Page 28: Getting Started with DOM - Part 1/3

HTMLElement / NODE_ELEMENTdataset

attributes

tagName

children

createElement()

getAttribute()

setAttribute()

hasAttribute()

removeAttribute()

classList()

Page 29: Getting Started with DOM - Part 1/3

HTMLElement / NODE_ELEMENT

innerHTML

innerText

outerHTML

textContent

insertAdjacentHTML()

Page 30: Getting Started with DOM - Part 1/3

HTMLElement / NODE_ELEMENT

appendChild()

removeChild()

replaceChild()

insertBefore()

cloneNode()