DOM Flashcards

1
Q

Why do we log things to the console?

A

for debugging or to know what you are working with

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

What is a “model”?

A

a representation or recreation of something that isn’t exact

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 object

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

What is a DOM Tree?

A

any element and holds all the configuration and the sum of all its parts

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

getElementId(), querySelector()

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

document.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

to use the variable and not calling the query function every time you need to use it

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() or dir method

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

to load all the content

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 a string element with css selector and matches it

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 element with css selector and node lists (collection of nodes)

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

Why do we log things to the console?

A

to debug and to know what you are working with

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

What is the purpose of events and event handling?

A

something occurred and information gets sent out also for allowing users to interact with the web page

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

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

addEventListener(), has 2 argument the string containing the event and the second argument is the callback function

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

What is a callback function?

A

when you pass a function as a value to another function

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

What object is passed into an event listener callback when the event fires?

A

an object with a huge list of properties to describe the event that just occurred

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
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 element where the event occurred. log it out or mdn.

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

What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())

A

the first one calls the function as a call back, while the second one calls the function immediately and nothing gets returned

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

What is the className property of element objects?

A

the value of the class attribute (not a selector)

22
Q

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

A

setAttribute() method

23
Q

What is the textContent property of element objects?

A

element . textContent

24
Q

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

A

element name with dot notation textContent “=” new string or variable

25
Is the event parameter of an event listener callback always useful?
no, but most of the time it will be
26
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
more complicated cause then you would have to code each "click"
27
Why is storing information about a program in variables better than only storing it in the DOM?
then you can use the variable instead of querying the dom element everytime
28
What event is fired when a user places their cursor in a form control?
focus()
29
What event is fired when a user's cursor leaves a form control?
blur()
30
What event is fired as a user changes the value of a form control?
input
31
What event is fired when a user clicks the "submit" button within a
?
submit event fires on the form element itself only
32
What does the event.preventDefault() method do?
prevents default behavior
33
What does submitting a form without event.preventDefault() do?
it allows the page to refresh and to submit the data to the same page
34
What property of a form element object contains all of the form's controls.
form.elements or the elements property
35
What property of a form control object gets and sets its value?
the value property
36
What is one risk of writing a lot of code without checking to see if it works so far?
you wont know what part is working or not working
37
What is an advantage of having your console open when writing a JavaScript program?
you can see if there is an error
38
Does the document.createElement() method insert a new element into the page?
No
39
How do you add an element as a child to another element?
appendChild() method
40
What do you pass as the arguments to the element.setAttribute() method?
(name of the attribute in a string, new value)
41
What steps do you need to take in order to insert a new element into the page?
createElement() -> make configurations (add text and class)-> querySelect for parent -> parent.appendChild().
42
What is the textContent property of an element object for?
text content
43
Name two ways to set the class attribute of a DOM element.
className or setAttribute()
44
What are two advantages of defining a function to create something (like the work of creating a DOM tree)?
you dont have to create a dom tree over and over again as well as gives reusability
45
What is the event.target?
the element that was clicked on or interacted with
46
Why is it possible to listen for events on one element that actually happen its descendent elements?
event bubbling to the top
47
What DOM element property tells you what type of element it is?
tag name property value all uppercase
48
What does the element.closest() method take as its argument and what does it return?
takes css selector as argument and returns the nearest parent element that matches with the css selector
49
How can you remove an element from the DOM?
element.remove()
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?