DOM Flashcards

1
Q

Why do we log things to the console?

A

verify values to help debug

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 entire page (html)

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

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

A

the entire page (html document)

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

What is a DOM Tree?

A

a model of the web page (html doc) as a javascript object

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

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

A

in case you need to work with the element more han once

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

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

A

the rest of the page must be loaded to create an accurate DOM tree

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 rest of the page must be loaded/created to create an accurate DOM tree

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

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

A

CSS selector; returns all matching element

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

CSS selector; returns all matching element in the form of a node list

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

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

A

a data type in javascript which can hold multiple items

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

Why do we log things to the console?

A

check things

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

What is the purpose of events and event handling?

A

respond to occurrences

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

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

A

.addEventListener()

17
Q

What is a callback function?

A

function definition being passed around as a value to be invoked later

18
Q

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

A

all possible data the browser feels would be pertinent to the event

19
Q

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

A

specifies where the event occurs

20
Q

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())

A

second snippet would result in an error as no arguments would have been passed in

21
Q

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

A

using the .className method

22
Q

What is the textContent property of element objects?

A

represents text content of the node

23
Q

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

A

get element from dom, then use textContent property to change

24
Q

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

A

no, event doesn’t always need to be used

25
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

significantly more complicated

26
Q

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

A

more readily available in a variable

also easier than searching through the entire DOM