DOM Flashcards

1
Q

Why do we log things to the console?

A

We could determine what the code is doing and help us debug.

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

What is a “model”?

A

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

objects in the model that represent a different part of the page loaded in the window and refers to javascript object.

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

What is a DOM Tree?

A

layer of how the browser structure the model.

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(‘id’), querySelector(‘css selector’)

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

getElementByClassName(),
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 store reference or location of an element you’re trying to retrieve into the variable so browser doesn’t have to keep going back to look for the element.

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

If the script is at the bottom, the html content can be uploaded first by the browser and then run javascript

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 css selectors as an argument and returns the first matching element.

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 css selectors as an argument and return all the matching elements - nodeList.

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

We log things to check our process and to debug

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

The purpose is to control user input specifically and user interaction by adding dynamic content.

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

e

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

e

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

What is a callback function?

A

when a function is passed into another function as an argument.

18
Q

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

A

e

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

place where the event occurred.

20
Q

What is the difference between these two snippets of code?

A

second one is calling the function, but calling it now and returns undefined since no argument is called.

21
Q

What is the className property of element objects?

A

The className property of the Element interface gets and sets the value of the class attribute of the specified element.

22
Q

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

A

Get that element from the dom and use new value, assign property

23
Q

What is the textContent property of element objects?

A

text inside of that element

24
Q

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

A

node.textContent

25
Q

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

A

By default when event handler functions are executed will pass the event object, so it is not always necessary. However, It is useful for the function to see the event that happened.

26
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 since there’s no measurement to see when to change the colors

27
Q

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

A

Storing information in variables allow us to see increments and change of values. For variables, value can change over time, therefore, it is easier to manipulate.

28
Q

What does the transform property do?

A

They let you rotate, scale, skew or translate an element

29
Q

Give four examples of CSS transform functions

A

rotate, translate, scale, skew, matrix

30
Q

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

A

no it does not put it on the page

31
Q

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

A

append, appendChild

32
Q

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

A

attribute you want to set and

33
Q

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

A

query select and create the element and put it inside the selected element

34
Q

What is the textContent property of an element object for?

A

get or set text content

35
Q

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

A

setAttribute() , className property, classList property

36
Q

What are the two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A

take in data and spit out the result of the data

37
Q

What is the event.target?

A

stores where the object originated from

38
Q

why is it possible to listen for events on one element that actually happen its descendent elements?

A

because of event bubbling

39
Q

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

A

event.target.tagName

40
Q

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

A

selector

41
Q

How can you remove an element from the DOM?

A

remove() need to call element that you want to remove

42
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

A