DOM Flashcards

(49 cards)

1
Q

Why do we log things to the console?

A

to verify code and get information about code

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

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

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

element + 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

getElementByID or 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

getElementsByClassName, getElementsByTagName, 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 reuse in the future (stores location of DOM)

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

load the content of all the elements, documents load from top to bottom

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

css selector syntax (string), returns only 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

css selector (string), returns 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

when an event “fires” , it can be used to trigger a particular function or code

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, not all parameters are required

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

A callback function is a function passed into another function as an argument

passing the definition of the function, not the return

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

event object that has data about the event that occured

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

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

event.target is the target element being used / originated from

console.log(event.target)

MDN

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

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

A

first code is using the handleClick function while the second code is calling the function

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

What is the className property of element objects?

A

gets and sets the value of the class attribute of the specified element.

21
Q

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

A

element.className

22
Q

What is the textContent property of element objects?

23
Q

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

A

element.textcontent = ‘string’

24
Q

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

25
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,
26
Why is storing information about a program in variables better than only storing it in the DOM?
27
What event is fired when a user places their cursor in a form control?
focus
28
What event is fired when a user's cursor leaves a form control?
blur
29
What event is fired as a user changes the value of a form control?
input
30
What event is fired when a user clicks the "submit" button within a
?
submit
31
What does the event.preventDefault() method do?
prevents default action of the event
32
What does submitting a form without event.preventDefault() do?
browser would reload the page with form's values in the URL
33
What property of a form element object contains all of the form's controls.
.elements
34
What property of a form control object gets and sets its value?
.value
35
What is one risk of writing a lot of code without checking to see if it works so far?
could be writing bugs
36
What is an advantage of having your console open when writing a JavaScript program?
when writing code, you can see errors as they happen
37
Does the document.createElement() method insert a new element into the page?
no, created and stored in a variable
38
How do you add an element as a child to another element?
.appendChild
39
What do you pass as the arguments to the element.setAttribute() method?
name, value (attribute name, value) ex. .setAttribute('class', 'click-button')
40
What steps do you need to take in order to insert a new element into the page?
create the element and store in a variable, give it content, call querySelector to find element and store in variable, append child and add it to the dom
41
What is the textContent property of an element object for?
to return all the text content including all elements (set or get)
42
Name two ways to set the class attribute of a DOM element.
.className property & .setAttribute() method
43
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
only have to write function once so it can be reusable, and have a name to reuse the function
44
What is the event.target?
where the event started element u clicked on
45
Why is it possible to listen for events on one element that actually happen its descendent elements?
event bubbling
46
What DOM element property tells you what type of element it is?
.tagName all caps
47
What does the element.closest() method take as its argument and what does it return?
string of a valid css selector return closest ancestor element or itself
48
How can you remove an element from the DOM?
.remove() method
49
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?
add event listener to an ancestor