DOM Flashcards

1
Q

Why do we log things to the console?

A

for debugging and an easy way to inspect your variables in the browser

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

What is a “model”?

A

representation of a person or thing or of a proposed structure, typically on a smaller scale than the original.

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 page

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

javscript objects

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

What is a DOM Tree?

A

When the browser loads a web page, it creates a model of the page in memory.

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

getElementByld(‘id’) , querySel ector(‘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

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

It stores the location of that elelment, properties and methods of that element work on the varaiable

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

linear, has to be at bottom so elements can load first

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

css selector and returns all matching element

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

for debugging and an easy way to inspect your variables in the browser

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

make webages interactable respond to the actions of the users

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

What do [] square brackets mean in function and method syntax documentation?

A

gives an option to use parameters

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(‘event’,function, flow = false)

17
Q

What is a callback function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

18
Q

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

A

the event object with a whole lot of information about the current info

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

The target property of the Event interface is a reference to the object onto which the event was dispatched. MDN

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

21
Q

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

A

.className

22
Q

What is the textContent property of element objects?

A

The textContent property of the Node interface represents the text content of the node and its descendants.

23
Q

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

A

textContent

objectname.textContent = ‘new string’;

24
Q

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

A

more work for the browser

25
Q

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

A

creates an element that can be added to the DOM tree

26
Q

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

A

appendChild()

27
Q

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

A

Element.setAttribute(name, value);

28
Q

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

A

document.createElement , appendChild()

29
Q

What is the textContent property of an element object for?

A

property of the Node interface represents the text content of the node and its descendants.

30
Q

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

A

setattribute and className property

31
Q

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

A

reusability and makes code look cleaner/easy to read