DOM Flashcards

1
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
2
Q

Which “document” is being referred to in the phrase Document Object Model?

A

html

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

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

A

object data type

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

What is a DOM Tree?

A

javascript object for an html element and its children containing attributes and values

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

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

A

to use in the future and easier to find

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

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

A

HTML content has to load first

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

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

A

string that contains CSS selector and returns DOM at first occurrence

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

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

A

string that contains CSS selector and returns Node list

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

What is the purpose of events and event handling?

A

interactivity

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

Are all possible parameters required to use a JavaScript method or function?

A

no, some parameters are optional

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

What is a callback function?

A

function passed as an argument in another function

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

object with all the data about

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

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

A

element WHERE the event occurred, check on MDN

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

What is the difference between these two snippets of code?

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

A
function definition
return value of the function call
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the className property of element objects?

A

he value of an element’s class attribute

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

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

A

object.className = ‘class’

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

What is the textContent property of element objects?

A

represents the text content of the node and its descendants

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

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

A

object.textContent = ‘text content’

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

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

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
Why is storing information about a program in variables better than only storing it in the DOM?
its easier to access and pass as arguments
26
What event is fired when a user places their cursor in a form control?
focus
27
What event is fired when a user's cursor leaves a form control?
blur
28
What event is fired as a user changes the value of a form control?
input
29
What event is fired when a user clicks the "submit" button within a ?
submit
30
What does the event.preventDefault() method do?
prevents the default behavior for the event
31
What does submitting a form without event.preventDefault() do?
page refreshes
32
What property of a form element object contains all of the form's controls.
elements property
33
What property of form a control object gets and sets its value?
value property
34
What is one risk of writing a lot of code without checking to see if it works so far?
harder to spot bug
35
What is an advantage of having your console open when writing a JavaScript program?
you know when somethings not working
36
Does the document.createElement() method insert a new element into the page?
no, it just creates it
37
How do you add an element as a child to another element?
.appendChild()
38
What do you pass as the arguments to the element.setAttribute() method?
('name of attribute', 'value of attribute')
39
What steps do you need to take in order to insert a new element into the page?
.createElement(), store new element, query for parent element, append onto parent
40
What is the textContent property of an element object for?
retrieve the text or change the text
41
Name two ways to set the class attribute of a DOM element.
setAttribute() or .className
42
What is the event.target?
element where the event occurred
43
Why is it possible to listen for events on one element that actually happen its descendent elements?
bubbling
44
What DOM element property tells you what type of element it is?
.tagName
45
What does the element.closest() method take as its argument and what does it return?
takes string of selector as argument and returns closest ancestor of the selected element
46
How can you remove an element from the DOM?
Element.remove()
47
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 event and check if type of event.target is what you want it on
48
What is the affect of setting an element to display: none?
does not display and taken out of document flow
49
what does the element.matches() method take as an argument and what does it return?
it takes a selector in a string and returns a boolean
50
How can you retrieve the value of an element's attribute?
.getAttribute()
51
At what steps of the solution would it be helpful to log things to the console?
every step where a value is changing
52
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?
make new event handler each time you add
53
What is a "callback" function?
function passed into another function as an argument
54
Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?
setTimeout( )
55
How can you set up a function to be called repeatedly without using a loop?
setInterval( )
56
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
57
What do setTimeout() and setInterval() return?
an positive integer ID used to pass to clearInterval ( )