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?

A

no

24
Q

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

A

focus

25
Q

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

A

blur

26
Q

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

A

input

27
Q

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

A

submit

28
Q

What does the event.preventDefault() method do?

A

Prevents the default action

29
Q

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

A

it reloads the page

30
Q

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

A

the elements property

31
Q

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

A

the form method

32
Q

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

A

No

33
Q

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

A

Append Child

34
Q

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

A

the name of the attribute and value

35
Q

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

A

Create element, query an element on the html document then appendChild the new element to the html element

36
Q

What is the textContent property of an element object for?

A

to set or get the text value of an element

37
Q

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

A

setAttribute, className

38
Q

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

A

you can use it more than once and its easily callable

39
Q

What is the event.target?

A

where the event started

40
Q

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

A

due to event bubbling

41
Q

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

A

tagName.property

42
Q

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

A

takes css selector and its first ancestor

43
Q

How can you remove an element from the DOM?

A

remove method

44
Q

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

A

string

45
Q

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

A

getAttribute