DOM Flashcards

1
Q

Why do we log things to the console?

A

to verify and check code

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

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

A

The 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

data type

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

What is a DOM Tree?

A

an element plus its content and configuration

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

If you want to use the same DOM element more than once

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

it needs to load all the elements

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

it takes strings as an argument and returns the first element that matches

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

it takes a string as an argument and returns a nodelist

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

it allows the developer to make changes when the user does something

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

What is a callback function?

A

taking a function definition and passing it down

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

target

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

What is the event.target?

A

the element where the event originated on

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

it holds the value of the class name property in an html document

20
Q

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

A

elementName.className = newClassName

21
Q

What is the textContent property of element objects?

A

it holds all the text that the element includes

22
Q

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

A

elementName.textContent = newText

23
Q

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

24
Q

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

25
What event is fired when a user's cursor leaves a form control?
blur
26
What event is fired as a user changes the value of a form control?
input
27
What event is fired when a user clicks the "submit" button within a
?
submit
28
What does the event.preventDefault() method do?
Prevents the default action
29
What does submitting a form without event.preventDefault() do?
it reloads the page
30
What property of a form element object contains all of the form's controls.
the elements property
31
What property of a form control object gets and sets its value?
the form method
32
Does the document.createElement() method insert a new element into the page?
No
33
How do you add an element as a child to another element?
Append Child
34
What do you pass as the arguments to the element.setAttribute() method?
the name of the attribute and value
35
What steps do you need to take in order to insert a new element into the page?
Create element, query an element on the html document then appendChild the new element to the html element
36
What is the textContent property of an element object for?
to set or get the text value of an element
37
Name two ways to set the class attribute of a DOM element.
setAttribute, className
38
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
you can use it more than once and its easily callable
39
What is the event.target?
where the event started
40
Why is it possible to listen for events on one element that actually happen its descendent elements?
due to event bubbling
41
What DOM element property tells you what type of element it is?
tagName.property
42
What does the element.closest() method take as its argument and what does it return?
takes css selector and its first ancestor
43
How can you remove an element from the DOM?
remove method
44
What does the element.matches() method take as an argument and what does it return?
string
45
How can you retrieve the value of an element's attribute?
getAttribute