DOM Flashcards

1
Q

Why do we log things to the console?

A

to check the output of your coding to see if it is working correctly

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

What is a “model”?

A

copy of the structure of an html document.

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 page.

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

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

A

javascript object.

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

What is a DOM Tree?

A

Data representation of all elements and its child elements.

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

Give two examples ofdocumentmethods that retrieve a single element from the DOM.

A

getelementbyid and query selector.

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

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

A

so that you can easily access that DOM variable. Reuse it.

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

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

A

so that body contents of html can load first.

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

What does queryselector take as its argument and what does it return?

A

string of css selector, first of the matching elements.

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

What does queryselectorall take as its argument and what does it return?

A

string of css selector, returns all of the elements that match.

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

events occur based on user interaction. Event handling are steps that lead to the trigger.

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

add 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

a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

17
Q

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

A

event object with a report on a specific event for you to work with.

18
Q

what is event.target? If you werent sure, how would you check? Where could you get more information about it?

A

a reference to the object onto which the event was dispatched. MDN

19
Q

What is the className property of element objects?

A

used to update classname attribute.

20
Q

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

A

Using className property

21
Q

What is textContent properly of element objects?

A

add or update text.

22
Q

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

A

use text content property

23
Q

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

A

no

24
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

25
Q

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

A

can make website load faster. Easier to maintain your code.

26
Q

What is event.target?

A

contains helpful data about the event, such as which element the event happened on.

27
Q

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

A

Bubble up to the parent elements. Event is carried forward to each ancestor chain.

28
Q

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

A

tagName, nodeName.

29
Q

what does the closest method take as its argument and what does it return?

A

String of css selector, returns Dom that matches that selector.

30
Q

How can you remove an element from the DOM?

A
  • remove() on the Dom element you want to remove.
31
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

you would add it to the parent element that retains all of the originating elements.