JS dom-querying, events, and manipulation Flashcards

1
Q

Why do we log things to the console?

A

to double check our work , inspect value

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

What is a “model”?

A

model is a replica of something/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

object is a datatype in javascript

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

What is a DOM Tree?

A

a javascript object for an html element- including all of its elements, attributes and all of its children

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

document.querySelector(‘element’)
getElementById(‘#idName’)
* can use querySelector for every thing*

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(‘element’)

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

in case you need to access that specific element multiple times

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 script tag need to be placed at the bottom of the HTML content instead of at the top?

A

browser needs to inspect entire document before javaScript can access them

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

takes a string and its css selector- return is the first element it finds that matches that 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

takes a string and its css selector and returns a node list of elements that match that selector

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 double check our work and inspect values

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

function passed into another function as an argument,

17
Q

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

A

an object with properties that contain all the data describing that event

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

where the event occurs (NOT the element that event is attached to)
-console.log and then MDN

19
Q

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())

A

the first one is being passed a function as an argument, the second one is calling that function and the return of that function is being passed before the event listener even happens

20
Q

What is the purpose of events and event handling?

A

keep track of user interaction

21
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

more complicated

22
Q

What is the className property of element objects?

A

shows the class name of the selected element and allows you to set it to a different one (GET or SET)

23
Q

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

A

property className

ex) element.className = ‘newClass’

24
Q

What is the textContent property of element objects?

A

shows the text content of the selected element and allows you to change it

25
Q

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

A

property textContent

ex) element.textContent = ‘newText content’

26
Q

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

A

no, but most of time it will be