DOM Flashcards

1
Q

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

A

takes a css selector and returns a node list

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

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

A

takes a css selector and returns a single node

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

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

A

so that everything else could load first

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

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

A

you use it frequently

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

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

A

objects are what comprise the web page

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

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

A

document node

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

What is a DOM Tree?

A

dom element with its components it consists of four nodes: document node, element nodes, attribute nodes, and text nodes

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

Why do we log things to the console?

A

we log things to the console to know what we are doing and to check that our work is valid

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

What is a “model”?

A

representation of something

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

Why do we log things to the console?

A

we log things to the console to know what we are doing and to check that our work is valid

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

user interactivity

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 object is passed into an event listener callback when the event fires?

A

event object; all of the data that a browser feels is pertinent to that event

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

the target property of the event interface is a reference to the object onto which the event was dispatched

check on mdn

basically, which object was the event acted upon?

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

the first is using a callback function while the second is immediately calling the function

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

the className property gets and sets the value of the class attribute of the specified element

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

use the className property

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

it is whatever text is written for the object

22
Q

What is the textContent property of element objects?

A

text inside of the element

23
Q

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

A

it is not 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

it would be more complicated because we would have to

25
Why is storing information about a program in variables better than only storing it in the DOM?
you don't have to keep searching for the information in the dom
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?
if the event does not get explicitly handled, its default action should not be taken as it normally would be
31
What does submitting a form without event.preventDefault() do?
it refreshes the page immediately
32
What property of a form element object contains all of the form's controls.
element
33
What property of form a control object gets and sets its value?
value
34
What is one risk of writing a lot of code without checking to see if it works so far?
one part of the code may be broken and it would be a hassle to track through all the code to find what is broken
35
What is an advantage of having your console open when writing a JavaScript program?
you can immediately detect when there is an error message
36
Does the document.createElement() method insert a new element into the page?
no
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, value
39
What steps do you need to take in order to insert a new element into the page?
query document, create element, append element
40
What is the textContent property of an element object for?
see the text content
41
Name two ways to set the class attribute of a DOM element.
className and setAttribute
42
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
reusability, no need to create another function in a different area so more control
43
Give two examples of media features that you can query in an @media rule
placeholder
44
Which HTML meta tag is used in mobile-responsive web pages?
placeholder
45
What is the event.target?
this is the element to which the event happened to
46
Why is it possible to listen for events on one element that actually happen to its descendent elements?
bubbling
47
What DOM element property tells you what type of element it is?
element.target.nodeName | tagName
48
What does the element.closest() method take as its argument and what does it return?
this traverses the element and its parent until it finds a node that matches the provided selector string and it will return itself or the matching ancestor; if no such element exists, it returns null
49
How can you remove an element from the DOM?
use .remove() method
50
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?
parent element