DOM Flashcards

1
Q

What is a “model”?

A

A visual representation

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

the HTML doc

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

a JavaScript Object

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

What is a DOM Tree?

A

An element plus all its content and its configuration

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() and preferably querySelector()

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

So you don’t need to keep looking it upon each reuse

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

 tag need to be placed at the bottom of the HTML content instead of at the top?
A

So it loads every element first before it loads up the javascript

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

Why would a

 tag need to be placed at the bottom of the HTML content instead of at the top?
A

So it loads every element first before it loads up the javascript

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

Takes CSS syntax as a string, returns the first element that it finds matching that selector

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

It takes a string and brings back a nodeList

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

What is the purpose of events and event handling?

A

To make the document behave with interactions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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
14
Q

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

A

addEventListener

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

What is a callback function?

A

taking a function definition and passing it around

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

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

A

data about the event that occurred

17
Q

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

A

A property that holds the element where the event originated from

17
Q

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

A

A property that holds the element where the event originated from

18
Q

What is the className property of element objects?

A

spaces separating class names

19
Q

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

A

string with classes separated by spaces

20
Q

What is the textContent property of element objects?

A

represents all the text of element and its children

21
Q

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

A

element name.textContent(‘string’)

22
Q

Is the event parameter of an event listener callback always useful?

A

sometimes no

23
Does the document.createElement() method insert a new element into the page?
No
24
How do you add an element as a child to another element?
appendChild
25
What do you pass as the arguments to the element.setAttribute() method?
name of the attribute, and the value
26
What steps do you need to take in order to insert a new element into the page?
createElement, store in var, call query selector for the element to appendChild
27
What is the textContent property of an element object for?
set or get text value of element
28
Name two ways to set the class attribute of a DOM element.
setAttribue(), className
29
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
reusability, and naming a process
29
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
reusability, and naming a process
30
What is the event.target?
where the event occurred
31
Why is it possible to listen for events on one element that actually happen its descendent elements?
bubbling
32
What DOM element property tells you what type of element it is?
tag name property in ALL CAPS
33
What does the element.closest() method take as its argument and what does it return?
takes a css selector and returns the first element it finds in its tree
34
How can you remove an element from the DOM?
remove() method
35
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?
Listening to a parent element
36
What is the event.target?
where the event happened from
37
What does the element.matches() method take as an argument and what does it return?
takes a string of a css selector, returns a boolean of if the element has that selector
38
How can you retrieve the value of an element's attribute?
getAttribute()
39
If you were to add another tab and view to your HTML, but you didn't use event delegation, how would your JavaScript code be written instead?
individual event listener for each tab