dom Flashcards

(72 cards)

1
Q

Why do we log things to the console?

A

to check for bugs and to see what things are

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

What is a “model”?

A

representation of something else

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 document node at the top of the tree

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

each node is an object with methods and properties

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

What is a DOM Tree?

A

A diagram showing parent to child and sibling relations between nodes.

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 .geElementById()

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

.getElementsByClassName()

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

so you don’t have to type the method out everytime to get the same DOM query

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

because the HTML content needs to be written before it can be called by the domquery.

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 selector and returns the first element int he document that matches the specified selector

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 returns a nodelist that matches a group of selectors.

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 see what’s happening and know where we are

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

execute code when an event occurs- have user interaction

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

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

What is a callback function?

A

function that is passed into another function as an argument which is then invoked inside the outer function to complete an action

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

the event

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

target property of the event object- holds element that was interacted with, console log event.target

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

handleclick() will run and what is returned is passed as the argument.
handleclick does not return and just runs when the click event happens

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

it is the class attribute of the element.

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

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

A

document.queryselector().className =

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

What is the textContent property of element objects?

A

shows the textcontent of the element

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

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

A

document.queryselector().textcontent =

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Is the event parameter of an event listener callback always useful?
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
27
Why is storing information about a program in variables better than only storing it in the DOM?
can call the variable at multiple locations and uses
28
What does the transform property do?
lets you rotate, scale, skew, or translate an element
29
Give four examples of CSS transform functions.
rotate, scale, skew, trasnlate
30
The transition property is shorthand for which four CSS properties?
transition-delay transition-duration transition-property transition-timing-function
31
What event is fired when a user places their cursor in a form control?
focus event
32
What event is fired when a user's cursor leaves a form control?
blur event
33
What event is fired as a user changes the value of a form control?
input event
34
What event is fired when a user clicks the "submit" button within a ?
submit event
35
What does the event.preventDefault() method do?
prevents the default action from taking place if the event is not explicitly handled
36
What does submitting a form without event.preventDefault() do?
resets the page
37
What property of a form element object contains all of the form's controls.
elements property
38
What property of a form control object gets and sets its value?
value property
39
What is one risk of writing a lot of code without checking to see if it works so far?
will have a difficult time seeing where the code went wrong if it doesn't work
40
What is an advantage of having your console open when writing a JavaScript program?
can see what is happening and see errors if they occur
41
Does the document.createElement() method insert a new element into the page?
No
42
How do you add an element as a child to another element?
append.child
43
What do you pass as the arguments to the element.setAttribute() method?
(attribute, value)
44
What steps do you need to take in order to insert a new element into the page?
make the element, append textnode into it if it has text, append the element to parent element on the page
45
What is the textContent property of an element object for?
to point to the textContent of the element
46
Name two ways to set the class attribute of a DOM element.
element.className = | setattribute(class, classname)
47
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
can call multiple times to create multiple trees for different data can have page interactions to call the function
48
What is the event.target?
target property of the event. the object onto which the event occured. element that started the event
49
Why is it possible to listen for events on one element that actually happen its descendent elements?
event bubbling
50
What DOM element property tells you what type of element it is?
.tagName
51
What does the element.closest() method take as its argument and what does it return?
a selector. returns closest matching element
52
How can you remove an element from the DOM?
.remove()
53
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?
create a container for them that has the event listener and filters for the element nodeNames or tags
54
What is the event.target?
target property of the event. the object onto which the event occured. element that started the event
55
What is the affect of setting an element to display: none?
it is hidden. removed from page
56
What does the element.matches() method take as an argument and what does it return?
returns a boolean
57
How can you retrieve the value of an element's attribute?
.getAttribute()
58
At what steps of the solution would it be helpful to log things to the console?
Any step that something is assigned or produces a value
59
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?
Would have to add an eventlistener to each tab
60
If you didn't use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
would have to hard code each tab[i] to check if it matched e.target and then hard code the addition or removal of classes
61
What is a breakpoint in responsive Web design?
The points at which a media query is introduced are known as breakpoints.
62
What is the advantage of using a percentage (e.g. 50%) width instead of a fixed (e.g. px) width for a "column" class in a responsive layout?
useful for different screen sizes
63
If you introduce CSS rules for a smaller min-width after the styles for a larger min-width in your style sheet, the CSS rules for the smaller min-width will "win". Why is that?
css cascading overrides with the latest introduced css ruleset
64
What is JSON?
javascript object notation
65
What are serialization and deserialization?
Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network.
66
Why are serialization and deserialization useful?
can store objects and send them
67
How do you serialize a data structure into a JSON string using JavaScript?
stringify
68
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse
69
How to you store data in localStorage?
localStorage.setitem()
70
How to you retrieve data from localStorage?
localStorage.getitem()
71
What data type can localStorage save in the browser?
JSON,
72
When does the 'beforeunload' event fire on the window object?
before the window, document, and its resources unload