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

complicated

27
Q

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

A

data accessibility

28
Q

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

A

data accessibility; keep it w/in js rather than dom

29
Q

Does the document.createElement() method insert a new element into the page?

A

no

30
Q

How do you add an element as a child to another element?

A

append child method

31
Q

What do you pass as the arguments to the element.setAttribute() method?

A

name of attribute and it’s respective object property

32
Q

What steps do you need to take in order to insert a new element into the page?

A

use a create element method of the document object

33
Q

What is the textContent property of an element object for?

A

the text content of the object and it’s children

34
Q

Name two ways to set the class attribute of a DOM element.

A

set attribute method and class name method

35
Q

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A

data respective

36
Q

What is the event.target?

A

getting the target of the event (object; most specific element interacted with); reference to the object onto which the event occurred

37
Q

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

A

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
Q

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

A

tagName; which is a read-only property of the element interface returns the tag name of the element on which it’s called

39
Q

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

A

arg: a selector list
return: element which is the closest ancestor of the selected element

40
Q

How can you remove an element from the DOM?

A

Element.remove() method removes the element from the tree it belongs to

41
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

Event delegation

42
Q

what is event delegation?

A

Event delegation allows you to avoid adding event listeners to specific nodes; instead, the event listener is added to one parent

43
Q

What is the event.target?

A

reference to the object onto which the event occurred

44
Q

What is the affect of setting an element to display: none?

A

will remove it from the accessibility tree

45
Q

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

A

arg: string representing the selector
return: boolean value

46
Q

How can you retrieve the value of an element’s attribute?

A

get attribute method

47
Q

At what steps of the solution would it be helpful to log things to the console?

A

each step continually

48
Q

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?

A

event capturing; add another event listeners to new tab node; least specific node to most specific

49
Q

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

check each attribute property of each element in separate conditionals