DOM Query Flashcards

1
Q

Why do we log things in the console?

A

debugging purposes.

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

What is a “model”?

A

a copy 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

referring to the data type object 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

is an element with all of its contents and objects represented in a dom tree.

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() and document.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

If you’re going to use it many times in your javascript.

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

What console method allows you to assign the return value of a DOM query to a variable?

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

so that when the webpage loads all the content of the web page has been loaded before the script.

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 selectors and returns their values.

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 selectors and it returns a 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

they’re listening for specific events or waiting. events are functions that “handle” the function that javascript is listening for.

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

create .addEventListener, the string

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

What is a callback function?

A

a function which is to be executed after another function has finished execution.

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

an object with a huge set of properties that set an event to occur.

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

it’s the element where the listener occured. log it out and look where it is.

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?

A

the first one actually passes the event listener. it runs right then when you put into the function.

20
Q

What is the className property of element objects?

A
21
Q

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

A
22
Q

What is the textContent property of element objects?

A

it allows you to update the text that is contained in the element.

23
Q

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

A

the variable.text content = ‘string’ + variable.

24
Q

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

A
25
Q

Why is storing information about a program in variables better than only storing it in the DOM?

A
26
Q

Does the document.createElement() method insert a new element into the page?

A
27
Q

How do you add an element as a child to another element?

A
28
Q

What do you pass as the arguments to the element.setAttribute() method?

A
29
Q

What steps do you need to take in order to insert a new element into the page?

A
30
Q

What is the textContent property of an element object for?

A

to add text to an element.

31
Q

Name two ways to set the class attribute of a DOM element.

A

className setAttribute()

32
Q

What are the two advantages

A
33
Q

What is the event.target?

A
34
Q

Why is it possible to listen for events on one element that actually happen in its descendant elements?

A

bubbling

35
Q

What DOM element property tells you what type of element it is?

A

tagName property. value has to be uppercase.

36
Q

What does the element.closest() method take as its argument and what does it return?

A

takes the argument closest to string. and returns the closest ancestor matching with the css selector.

37
Q

How can you remove an element from the DOM?

A

element.remove()

38
Q

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?

A

add an eventListener to the ancestor. it’s called event delegation.

39
Q

What is the event.target?

A

element interacted with.

40
Q

What is the affect of something an element to display: none?

A

makes it so that it’s not visible. it’s still present though.

41
Q

What does the element.matches() method take as an argument and what does it return?

A

takes a css selector and returns a boolean whether or not it matches the selector.

42
Q

How can you retrieve the value of an element’s attribute?

A

element.getAttribute()

43
Q

At what steps of the solution would it be helpful to log things to the console?

A

every new line of code.

44
Q

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?

A

conditionals for each individual view.

45
Q

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?

A
46
Q

What is a breakpoint in responsive web design?

A