LFZ DOM Quiz Flashcards

1
Q

Why do we log things to the console?

A

For debugging purposes

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

What is a “model”?

A

a representation of something

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 HTML Document

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

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

A

getElementById, and querySelector

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

getElementsByClassName

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

To cache the location of the element so that the browser doesn’t have to find the element all over again

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

To cache the reference of the element so that the browser doesn’t have to find the element all over again

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

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

A

So that the browser can analyze all of the data in the HTML

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

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

A

it takes in a css selector and returns a nodelist of all elements with the css class

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

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

A

it takes in a css selector and returns the first element it finds that matches

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

Why do we log things to the console?

A

For debugging things

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

To listen for things like mouse click, key down, etc

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

To listen for things like mouse click, key down, etc and then do things

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

addEventListener

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

What is a callback function?

A

A call back function is a function that takes in a function as an argument

17
Q

What is a callback function?

A

A call back function is a function that takes in a function as an argument and runs it

18
Q

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

A

an event object

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

The target element of the event, you can check the documentation, or you can log the value to the console

20
Q

What is the difference between these two snippets of code?

A

The first one is passing the function through

The second one is calling the function and running the code

21
Q

What is the className property of element objects?

A

The class of the element

22
Q

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

A

by changing the className property

23
Q

What is the textContent property of element objects?

A

the text content of the element. It excludes markup

24
Q

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

A

by changing the textContent property of the selected element

25
Q

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

A

no

26
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

More complicated

27
Q

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

A

Simpler

28
Q

What is the event.target?

A

The target node of the event

29
Q

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

due to event bubbling. Clicking on a child element, also targets parent elements

30
Q

What DOM element property tells you what type of element it is?

A

event.tagName

31
Q

What does the element.closest() method take as its argument and what does it return?

A

It takes in a css selector and returns the closest parent that has that tag. Can return itself

32
Q

How can you remove an element from the DOM?

A

with the remove method

33
Q

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?

A

By putting the event listener on a parent container, and appending the new element as a child to that parent