DOM Properties & Methods Flashcards

1
Q

document.activeElement

A

DOM property that returns the element that has focus (read only)

const focus = document.activeElement
                  .tagName;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

.baseURI

A

Property that returns the base URI of the document (read only)

let base = document.baseURI;

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

.body

A

The body property sets or returns the body element.

const docBody = document.body.innerHTML;
//returns all the HTML content

document. body.style… //changes CSS
document. body.innerHTML = “whole new HTML content”;

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

.cookie

A

Property that sets or returns a semi-colon-separated list of key value pairs

let cookieList = document.cookie;

document.cookie = “name=joe; surname=smith”;

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

.documentURI

A

sets or returns a documents location

returns null if document was created in memory

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

.domain

A

returns the domain name of the server

returns null if the document is created in memory

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

.embeds

A

returns a collection of all ‘embed’ elements in the document (read only)

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

.forms

A

returns a collection of all ‘form’ elements in the document (read only)

let formCount = document.forms.length;

let id = document.forms[0].id;

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

.head

A

returns the head element of the document

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

document.images

A

returns a collection of all ‘img’ elements in the document

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

document.links

A

returns a collection of all ‘a’ and ‘area’ elements with href attributes

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

document.URL

A

returns the full document URL

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

What is an HTML collection? What are the three properties?

A

An HTMLCollection is a list of HTML elements.
The elements in a collection can be accessed by index (starts at 0).

.length; returns the number of elements
.item(); returns the element at a specified index
.namedItem(); returns the element with a specific id

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

What are the differences between HTMLcollection and NodeList?

What methods create each?

A

HTMLcollection is live, if an element is added to the DOM, the list will also change. [getElementsByClassName(), getElementsByTagName()]

NodeList is a static collection, the list will not change if an element is added to the DOM. [querySelectorAll(), childNodes, getElementsByName()]

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

What is a NodeList, what are its six properties?

A

A NodeList is a static collection (list) of Node Objects.
The nodes in a NodeList can be accessed by index (starts at 0).

.length; returns the number of nodes
.entries(); returns an iterator with key:value pairs
.forEach(); executes a callback function for each node
.item(); returns the node at the specified index
keys(); returns an iterator with the keys from the list
.values() returns an iterator with the values from the list

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

What is a DOMTokenList? How is it created?

A

A DOMTokenList is a set of space separated tokens.
That can be accessed by index (starts at 0).

The set is created with the classList property of an HTML element.

17
Q

What are the properties and methods of a DOMTokenList?

A

.add() .remove() .replace() .contains() .length .forEach()

.entries(); returns an iterator key:value pairs
.keys() .values()

.item() returns the token at a specified index
.supports() returns true if a token is one of an attribute’s supported tokens
.toggle() toggles between tokens in the list

18
Q

What is a NamedNodeMap? How is one created?

What are its properties and methods?

A

A NamedNodeMap is an unordered collection of an element’s attributes.
In other words: a NamedNodeMap is a list of Attr objects (HTML attributes).

const nodeMap = document.getElementById(“id”).attributes;

.name; //returns an attribute's name
.value; //sets/returns an attribute's value
.specified; //boolean on if the attribute is specified
.length;
.getNamedItem() //returns a node by name
.item() // returns a node by index
.removeNamedItem()
.setNamedItem()
19
Q

.addEventListener()

.removeEventListener()

A

.addEventListener() //attaches an event handler

.removeEventListener() //removes

(also used on elements)

20
Q

document. querySelector()

document. querySelectorAll()

A

.querySelector() //returns the first element that matches the a specific CSS selector

.querySelectorAll() //returns a static NodeList of all elements that match the selector

(can also be used on elements)

21
Q

.getElementsByClassName()

.getElementsByTagName()

A

.getElementsByClassName() //returns an HTMLcollection containing all elements with the class name

.getElementsByTagName() //returns an HTMLcollection with all elements that have the specified tag name

(also used on elements)

22
Q

.open()

.write()

.close()

A

!!! replaces entire document !!!
document.open() //Opens an HTML output stream to collect output from .write()

document.write(“h1Hello World!/h1”) //does not add a new line

.writeln() //adds a new line

document.close() //Closes the output stream previously opened with .open()

23
Q

What are the methods to create nodes/events within the document?

A

.createAttribute()
.createDocumentFragment()
.createTextNode()

.createElement()
.createEvent()
.createTextNode()

.createComment()

24
Q

.adoptNode()

.importNode()

.cloneNode()

A

.adoptNode() // The adopted node can be of all types.
Any child nodes (descendants) of the adopted node, are also adopted.
The original node (with child nodes) is removed from the other document.

.importNode() // The imported node is not removed from the original document. The imported node is a copy of the original. Can use a 2nd parameter set to true to import child nodes.

.cloneNode() // creates a copy of a node, and returns the clone. (attributes and values too) use the deep parameter of true if you want descendants.

25
Q

.getElementById()

A

returns the element that has the specified id value

26
Q

.getElementsByName()

A

Returns a live Nodelist containing all elements with the specified name.

27
Q

document.normalize()

A

removes empty text nodes, and joins adjacent text nodes.

28
Q

document.hasFocus()

A

Returns a true if the document (or any element in the document) has focus.
Otherwise it returns false.

29
Q

document.title

A

sets or returns the title of the document (in the head)

30
Q

document.documentURI

A

property sets or returns a document’s location.

returns null if the document was created in memory.

31
Q

document.documentElement

A

returns the whole HTML element

32
Q

document.readyState

A

returns the loading status of the document

33
Q

What scope do DOM object have?

How does this impact your code?

A

DOM objects have global scope

This means that if we want to contain functionality in a local scope, we cannot contain the DOM functions or objects.