DOM(Document Object Model) Flashcards

1
Q

Why do we log things to the console?

A

SO we can see what’s going on. Better than guessing.

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

For this one HTML, API

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

attribute nodes or text nodes

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

What is a DOM Tree?

A

It can be thought of as a tree with a single parent stem that branches out into several child branches.

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

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 we need to work with an element more than once.

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

The browser needs to parse all of the elements in the HTML page before the JavaScript code 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 css selector as string?

returns the first element that matches a css 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

NodeList representing a list of the document’s elements that match the specified 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 check if it’s working.

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

to callback events??

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

A function passed into another function as an argument

18
Q

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

A

event object?

19
Q

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

20
Q

What is the difference between these two snippets of code?

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

A

with the handleclick(), it can’t do anything cuz it’s not calling function

21
Q

What is the className property of element objects?

A

set or return the value of an element’s class attribute

22
Q

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

A

document.queryseletor(css selector).className = string of the class name

23
Q

What is the textContent property of element objects?

A

sets or returns the textual content of the specified node, and all its descendants.

24
Q

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

A

elemet.textContent = ‘’

25
Q

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

A

Not always

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

Would say harder.

27
Q

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

A

Numbers aren’t DOM element, so we need to use a variable to assign a numeric values.

28
Q

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

A

No it doesn’t

29
Q

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

A

appendchild

30
Q

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

A

pass the values of the attributes and the values as string

31
Q

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

32
Q

What is the textContent property of an element object for?

A

generate texts to the nodes.,

33
Q

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

A

setAttribute, classname

34
Q

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

A

To repeat

We can change it any time we want.

35
Q

What is the event.target?

A

reference to the object onto which the event was dispatched. point of interaction

36
Q

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

A

The event bubbling: The event starts at the most specific node and flows outwards to the least specific one., it’s the default

37
Q

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

38
Q

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

A

takes css selector, and it returns the closest parent element. also could return iself

39
Q

How can you remove an element from the DOM?

A

.remove() method

40
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

Use bubbling