DOM Flashcards

1
Q

Why do we log things to the console?

A

In order to check and debug our work

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

What is a “model”?

A

DOM is a representation (a separate entity)

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

DOCTYPE Html

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

Data type (or type of Data)

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

What is a DOM Tree?

A

Is a JS object for html element including its elements, attributes, values, children, and 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

getElementByID

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

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

Easier to retrieve data, which makes it easy to retrieve

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

Html loads from top to bottom

Needs to parse all the elements before

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

Returns only the first of the matching elements (selectors for css)

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

Returns all of that matches the called element (selector for css)

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

To create a reaction from the user upon action

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

Not always necessary

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

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.
It’s in the event listener

17
Q

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

A

Is an object with huge amount of properties that just occurred (storing lots of data)

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

Is the point of interaction
Element that dispatches the event

Console.log where the event occurred
If there is a div… and there is a button… the target will be button

19
Q

What is the difference between these two snippets of code?

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

A

handleClick - is a callback function

element.addEventListener(‘click’, handleClick()):
Functions values get RETURNED
This will be undefined
ex) if it gets checked… and stops
EventListener will never be called by user. It’s called by JS

20
Q

What is the className property of element objects?

A
It’s the property of the element that sets the value of class attribute 
ex) gettingHot.className
This holds the class name value 
Get a new value or set a new value
21
Q

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

A

You would assign a new value to the object.className or variable.className
Simply assign new value to it

22
Q

What is the textContent property of element objects?

A

Get or set
textContent property represents the text content of the node and its descendants
textContent returns every element in the node…
(innerText will not return the text of hidden elements)
Example: Var example = document.getElementById(‘diva’).textContent

23
Q

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

A

You assign the query the DOM to a variable

And assign new variable.ClassName to a new string

24
Q

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

A

yes

25
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

Simpler with variables

26
Q

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

A

Because you can manipulate the variables to be edited and store functions to use for later
Example is countingClicks.textContent = ‘Clicks: ‘ + storageNumberOfClicks

27
Q

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

A

No, it is not added yet
The element node is created
This is stored in a variable

28
Q

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

A

Use the .append() method

29
Q

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

A

With its name and value

30
Q

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

A

Step 1: createElement() method
Step 2: createTextNode() method (giving it content)
Step 3: appendChild() method (adding to DOM tree, specifies which element)

31
Q

What is the textContent property of an element object for?

A

For strings

32
Q

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

A

className method

setAttribute method

33
Q

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

A

You can loop through each of the items and manipulate it.

34
Q

What is the event.target?

A

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