DOM Flashcards

1
Q

Why do we log things to the console?

A

to check the output and help debug

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

What is a “model”?

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

HTML document

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

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
5
Q

What is a DOM Tree?

A

Every element, attribute, and piece of text in the HTML is represented by its own DOM node, which makes up the DOM tree

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

To save the location; saves the browser from having to look for it every time.

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 a tag need to be placed at the bottom of the HTML content instead of at the top?

A

HTML document needs to loads first so javascript can manipulate DOM

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

CSS selector string and returns only the first of the matching elements

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

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

A

CSS selector string and returns all 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 inform us of user interaction and event handling instructs how to respond to the event

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

What do [] square brackets mean in function and method syntax documentation?

A

denotes optional

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

What is a callback function?

A

a function passed into another function as an argument

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

event?

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

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

A

event object

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

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

A

target property of event; mdn

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

What is the difference between these two snippets of code?

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

A

presence of parentheses;
the parentheses are omitted where the function is called because they would indicate that the function should run as the page loads (rather than when the event fires)

20
Q

What is the className property of element objects?

A

DOM property that sets the value of the class attribute of the specified element

21
Q

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

A

className property

22
Q

What is the textContent property of element objects?

A

property that represents the text of the node and its descendants; allows text to be collected/updated

23
Q

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

A

textContent property

24
Q

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

A

no, because it is not always needed

25
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
more difficult
26
Why is storing information about a program in variables better than only storing it in the DOM?
to avoid having to search for the information every time that it is needed
27
Does the document.createElement() method insert a new element into the page?
no, simply creates an element that can be added to the DOM tree
28
How do you add an element as a child to another element?
using appendChild()
29
What do you pass as the arguments to the element.setAttribute() method?
string attribute name and attribute value
30
What steps do you need to take in order to insert a new element into the page?
createElement(), pick the spot you want to place it in, appendChild()
31
What is the textContent property of an element object for?
represents the text content of the node and its descendants.
32
Name two ways to set the class attribute of a DOM element.
.className and setAttribute()
33
What are two advantages of defining a function to create something (like the work of creating a DOM tree)?
reusable, saves time, and minimizes errors?
34
Why is it possible to listen for events on one element that actually happen its descendent elements?
event bubbling from most specific to least specific
35
What DOM element property tells you what type of element it is?
tagName property
36
What does the element.closest() method take as its argument and what does it return?
takes a string CSS selector as an argument and returns the closest element (which can be itself)
37
How can you remove an element from the DOM?
.remove()
38
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?
addEventListener to parent rather than the individual child nodes AKA event delegation
39
What is the event.target?
a reference to the object onto which the event was dispatched
40
What is the affect of setting an element to display: none?
Turns off the display of an element so that it has no effect on layout
41
What does the element.matches() method take as an argument and what does it return?
takes a css string selector as the argument and returns a boolean
42
How can you retrieve the value of an element's attribute?
.getAttribute()
43
At what steps of the solution would it be helpful to log things to the console?
after variable declarations
44
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?
add individual addEventListeners to each child node
45
If you didn't use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
a lot of individual conditionals