dom Flashcards

1
Q

Why do we log things to the console?

A

access of value

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

What is a “model”?

A

representation of a structure

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

js object; a object that is modeling the object document

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

What is a DOM Tree?

A

object model; model made of objects; stored in browser’s memory

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

querySelector(), getElementById()

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

reuse the method

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

method dir of object console; 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

gives the HTML time to load before any of the JavaScript loads, which can prevent errors

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

arg: a string css selector
return: first of the matching elements from top

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

arg: a string css selector
return: node list of one element object for each element that matches the css selector

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

dom node?

A

an object with methods and properties; every node is a descendant of the document node

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

Why do we log things to the console?

A

.

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

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

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

A

the event object

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

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

A

the event object; just a report on that event

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
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 property at the event object; a reference to the object onto which the event was dispatched; mdn

21
Q

What is the className property of element objects?

A

retrieve/assign the value of an element’s class attribute

22
Q

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

A

query and assign a new variable to the className property

23
Q

What is the textContent property of element objects?

A

add or update text w/in a dom element

24
Q

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

A

use the textContent property to the element

25
Is the event parameter of an event listener callback always useful?
no
26
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
complicated
27
Why is storing information about a program in variables better than only storing it in the DOM?
data accessibility
28
Why is storing information about a program in variables better than only storing it in the DOM?
data accessibility; keep it w/in js rather than dom
29
Does the document.createElement() method insert a new element into the page?
no
30
How do you add an element as a child to another element?
append child method
31
What do you pass as the arguments to the element.setAttribute() method?
name of attribute and it's respective object property
32
What steps do you need to take in order to insert a new element into the page?
use a create element method of the document object
33
What is the textContent property of an element object for?
the text content of the object and it's children
34
Name two ways to set the class attribute of a DOM element.
set attribute method and class name method
35
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
data respective
36
What is the event.target?
getting the target of the event (object; most specific element interacted with); reference to the object onto which the event occurred
37
Why is it possible to listen for events on one element that actually happen its descendent elements?
event bubbling: the event starts at the most specific node and flows outwards to the least specific one; the default type of event flow
38
What DOM element property tells you what type of element it is?
tagName; which is a read-only property of the element interface returns the tag name of the element on which it's called
39
What does the element.closest() method take as its argument and what does it return?
arg: a selector list return: element which is the closest ancestor of the selected element
40
How can you remove an element from the DOM?
Element.remove() method removes the element from the tree it belongs to
41
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?
Event delegation
42
what is event delegation?
Event delegation allows you to avoid adding event listeners to specific nodes; instead, the event listener is added to one parent
43
What is the event.target?
reference to the object onto which the event occurred
44
What is the affect of setting an element to display: none?
will remove it from the accessibility tree
45
What does the element.matches() method take as an argument and what does it return?
arg: string representing the selector return: boolean value
46
How can you retrieve the value of an element's attribute?
get attribute method
47
At what steps of the solution would it be helpful to log things to the console?
each step continually
48
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?
event capturing; add another event listeners to new tab node; least specific node to most specific
49
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?
check each attribute property of each element in separate conditionals