JavaScript - The Document Object Model Flashcards

1
Q

The Document Object Model (DOM) provides a way to ____ and _____ the contents of a web page.

A

The Document Object Model (DOM) provides a way to access and alter the contents of a web page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The DOM allows us to ___/____ or ___ elements, attributes and structure.

A

The DOM allows us to add/modify or remove elements, attributes and structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The _________ is the document that is referred to in “Document Object Model”. JavaScript uses specific terms to refer to parts (page objects) of the document.

A

The webpage is the document that is referred to in “Document Object Model”. JavaScript uses specific terms to refer to parts (page objects) of the document.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The DOM represents a document with a ____ _____. Each branch of the tree ends in a node, and each node contains objects. DOM methods allow programmatic _____ to the tree; with them you can change the document’s ______, ______, or ______. Nodes can also have event handlers attached to them; once an event is triggered, the event handlers get executed.

A

The DOM represents a document with a logical tree. Each branch of the tree ends in a node, and each node contains objects. DOM methods allow programmatic access to the tree; with them you can change the document’s structure, style, or content. Nodes can also have event handlers attached to them; once an event is triggered, the event handlers get executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Every document is made up of “_____”. There are different types of nodes, primarily, _____, ______ and _____.

A

Every document is made up of “nodes”. There are different types of nodes, primarily, element, attributes and text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

We can use these nodes to _____ specific parts of the document

A

We can use these nodes to target specific parts of the document

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If you need to address the text of a paragraph, you need to target the _____ _____ of the paragraph NOT the _______ _______.

A

If you need to address the text of a paragraph, you need to target the text node of the paragraph NOT the paragraph itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Targeting elements nodes is used often. JavaScript can target elements easily via ______ and _____.

A

Targeting elements nodes is used often. JavaScript can target elements easily via classes and ids.

Example:
//returns a node
var node = document.getElementById("id");
//returns an element list of nodes
var nodeList = document.getElementsByTagName("tagName"); 
//returns an element list of nodes (HTML5 only)
var nodeList = document.getElementsByClassName("className");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

With modern browsers, you are able to target elements using _____ _______.

A

With modern browsers, you are able to target elements using CSS selectors.

//returns the first node that matches the selector
var node = document.querySelector(selectors);
//Returns a list of nodes that match the specified group of selectors
var nodeList = document.querySelectorAll(selectors);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The query selector will only work for CSS selectors that the browser _______.

A

The query selector will only work for CSS selectors that the browser recognizes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

However, elements may be targeted relative to other elements;

A
//targets elements that are children of parentElement
var nodeList = parentElement.getElementsByTagName("tagName");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Give an example of how to modify content:

A
//creates a new  element node
var newElement = document.createElement("elementType")
//creates a new  text node
var textNode = document.createTextNode("some text here"); 
//appends the node to the parent as its last child
parentElement.appendChild(node); 
//inserts a new element before the target element where both elements are children of parentElement
parentElement.insertBefore(newElement, targetElement);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Creating all of your elements using JavaScript enables greater _______ of your application, including performance. Therefore, developers do not target elements as described above, they reference existing JavaScript variables. Effectively managing this technique leads into more advanced concepts. Modern frameworks apply this technique. More on that later.

A

Creating all of your elements using JavaScript enables greater control of your application, including performance. Therefore, developers do not target elements as described above, they reference existing JavaScript variables. Effectively managing this technique leads into more advanced concepts. Modern frameworks apply this technique. More on that later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Give an example of how to modify attributes:

A

document.getElementById(‘linkId’).href = “http://www.google.com”;
myEl.getAttribute(“src”); myElemnt.setAttribute(“src”,”images/image2.jpg”); //created if doesnt exist.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Give an example of how to modify styles:

A

document.getElementById(“p2”).style.color=”blue”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Give an example of how to remove elements:

A
var targetP = document.getElementById("p2");
targetP.parentNode.removeChild(targetP);
//or use the convenience function
targetP.remove();
17
Q

Classes can be _____ or ______ as necessary.

A

Classes can be added or removed as necessary.

18
Q

Modifying the _____ or _____ attributes can affect the look and feel of the entire page.

A

Modifying the class or id attributes can affect the look and feel of the entire page.

19
Q

List some properties:

A
nodeType
nodeName
nodeValue
innerHTML
childNodes
id
style
firstChild
nextElementSibling
20
Q

List some methods:

A
appendChild(child);
getAttribute( name )
getElementsByClassName(name)
insertBefore( insertedNode, adjacentNode )
removeChild( removedNode )
setAttribute( name, value )
21
Q

Some elements may have unique properties and methods. e.g. The video element has a ._______ property and ._____() and ._____() methods.

A

Some elements may have unique properties and methods. e.g. The video element has a .currentTime property and .play() and .pause() methods.

22
Q

There a a few built-in arrays that allow us to access certain types of elements on the page:

A
  • document.forms
  • document.links
  • document.images
  • document.body
23
Q

document.forms

A

document.forms is an array containing references to all the forms on the page.

24
Q

document.links

A

document.links is an array containing references to all the links on the page.

25
Q

document.images

A

document.images is an array containing references to all the images on the page.

26
Q

document.body refers to the _____

A

document.body refers to the body

27
Q

The DOM is a subset of the_______, the _______. Apart from the document, JavaScript can be used to script other parts of the browser including the _____, ________, _______, ______ and ________.

A

The DOM is a subset of the BOM, the Browser Object Model. Apart from the document, JavaScript can be used to script other parts of the browser including the screen, location, history, status and navigator.

28
Q

When we refer to document.getElementById, it is actually window.document.getElementById. window is the _______ object.

A

When we refer to document.getElementById, it is actually window.document.getElementById. window is the global object.

29
Q

The window object represents an _____ ____ ___ _____ _______.

A

The window object represents an open window in a browser.

30
Q

If a document contain frames ( tags), the browser creates one _______ object for the HTML document, and one additional ______ object for each frame.

A

If a document contain frames ( tags), the browser creates one window object for the HTML document, and one additional window object for each frame.