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?

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

its easier to access and pass as arguments

26
Q

What event is fired when a user places their cursor in a form control?

A

focus

27
Q

What event is fired when a user’s cursor leaves a form control?

A

blur

28
Q

What event is fired as a user changes the value of a form control?

A

input

29
Q

What event is fired when a user clicks the “submit” button within a ?

A

submit

30
Q

What does the event.preventDefault() method do?

A

prevents the default behavior for the event

31
Q

What does submitting a form without event.preventDefault() do?

A

page refreshes

32
Q

What property of a form element object contains all of the form’s controls.

A

elements property

33
Q

What property of form a control object gets and sets its value?

A

value property

34
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

harder to spot bug

35
Q

What is an advantage of having your console open when writing a JavaScript program?

A

you know when somethings not working

36
Q

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

A

no, it just creates it

37
Q

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

A

.appendChild()

38
Q

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

A

(‘name of attribute’, ‘value of attribute’)

39
Q

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

A

.createElement(), store new element, query for parent element, append onto parent

40
Q

What is the textContent property of an element object for?

A

retrieve the text or change the text

41
Q

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

A

setAttribute() or .className

42
Q

What is the event.target?

A

element where the event occurred

43
Q

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

A

bubbling

44
Q

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

A

.tagName

45
Q

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

A

takes string of selector as argument and returns closest ancestor of the selected element

46
Q

How can you remove an element from the DOM?

A

Element.remove()

47
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

addEventListener to parent event and check if type of event.target is what you want it on

48
Q

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

A

does not display and taken out of document flow

49
Q

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

A

it takes a selector in a string and returns a boolean

50
Q

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

A

.getAttribute()

51
Q

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

A

every step where a value is changing

52
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

make new event handler each time you add

53
Q

What is a “callback” function?

A

function passed into another function as an argument

54
Q

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?

A

setTimeout( )

55
Q

How can you set up a function to be called repeatedly without using a loop?

A

setInterval( )

56
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0

57
Q

What do setTimeout() and setInterval() return?

A

an positive integer ID used to pass to clearInterval ( )