DOM Flashcards

1
Q

What is a “model”?

A

The Document Object Model (DOM) is the data representation of the objects that comprise the structure and content of a document on the web.

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

Which “document” is being referred to in the phrase Document Object Model?

A

Every element, attribute and piece of text is represented by its own dom node.

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

What is the word “object” referring to in the phrase Document Object Model?

A

Each element of the document (which is a node) is represents as an object with its properties

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

What is a DOM Tree?

A

Relationships between the document and all of the element nodes and all of their child nodes and text nodes

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

Give two examples of document methods that retrieve a single element from the DOM.

A
  • getElementById()

- querySelector() - use this

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

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

querySelectorAll()

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

Why might you want to assign the return value of a DOM query to a variable?

A

When you need to work with an element more than once, you should use a variable to store the result of this query.

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

What console method allows you to inspect the properties of a DOM element object?

A

console.dir()

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

Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?

A

The browser needs to parse all the elements in the HTML page before JavaScript code can access them.

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

What does document.querySelector() take as its argument and what does it return?

A

String value containing a css selector and returns the first element that contains it

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

What does document.querySelectorAll() take as its argument and what does it return?

A

String value that is a css selector and returns a nodelist of all elements found with that selector

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

What should we start variable names with if it deals with DOM content?

A

Use a dollar sign $

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

What is the purpose of events and event handling?

A

Event are fired to notify code of outside changes that may affect code execution (event handling) like an action that occurs as a result of the user, like a mouse click (event)

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

Are all possible parameters required to use a JavaScript method or function?

A

No

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

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

Event Listener

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

What is a callback function?

A

Function being passed around as a value; Not being invoked but passing around.

17
Q

What object is passed into an event listener callback when the event fires?

A

An event object

18
Q

What is theevent.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

Element where the event occured

-MDN

19
Q

What is theclassNameproperty of element objects?

A

Sets or returns the class name of the element

20
Q

How do you update the CSS class attribute of an element using JavaScript?

A
  • query the dom for the element and assign a new value to the className property
21
Q

What is thetextContentproperty of element objects?

A

Sets or returns the text content of a specific node

22
Q

How do you update the text within an element using JavaScript?

A

Use the .textContent property onto the node object.

23
Q

Is theeventparameter of an event listener callback always useful?

A

No, it can be ignored.

24
Q

Why is storing information about a program in variables better than only storing it in the DOM?

A

Yes, so the DOM doesn’t have to look over each memory node.

25
Does the document.createElement() method insert a new element into the page?
No, it attaches it to DOM Tree
26
How do you add an element as a child to another element?
.appendChild()
27
What do you pass as the arguments to the element.setAttribute() method?
$element.setAttribute( " attribute name " , value )
28
What steps do you need to take in order to insert a new element into the page?
1) Create the Element w/ .createElement 2) Add textContent or className 3) Append it to something that is already queried
29
What is the textContent property of an element object for?
Setting or returning the text content of a node element
30
Name two ways to set the class attribute of a DOM element.
.setAttribute() method or .className on a node element (more preferred)
31
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
Create copies easily. ex) Pokedex, we want a gallery on separate pages. By having the html skeleton structure, we can do so.
32
What is the event.target?
- A property returns which DOM element triggered the event. | - The element that is immediately interacted with
33
Why is it possible to listen for events on one element that actually happen its descendent elements?
Event is carried forward to every element above that element. Each element gets that exact event
34
What DOM element property tells you what type of element it is?
.tagName (meant for element) | .nodeName
35
What does the element.closest() method take as its argument and what does it return?
String of a css selector, and returns the most immediate one
36
How can you remove an element from the DOM?
Using .remove() on the dom element
37
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
Add it 1 layer higher, and wait for events to be fired.