DOM Querying, Events, and Manipulation Flashcards

1
Q

What is the className property of element objects?

A

It grabs and sets the value of the class

It’s a property holding the class value of the element

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

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

A

className = ‘new-value’

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

What is the textContent property of element objects?

A

Whatever text is inside of the element and it’s children elements

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

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

A

div1.textContent = ‘New value’

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

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

A

Not always

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

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

A

So we can reuse this information/data more easily

It makes the browser run more processes and do more work

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

Why do we log things to the console?

A

To test and communicate with our code and see if it is working as intended

Debugging and double checking your value

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

What is a “model”?

A

A representation/recreation of something

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

Which “document” is being referred to in the phrase Document Object Model?

A

It represents the entire web page. It is the starting point to the DOM Tree

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

What is the word “object” referring to in the phrase Document Object Model?

A

Objects are nodes within the DOM Tree

They represent every single element in the HTML document

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

What is a DOM Tree?

A

A map of all elements and nodes that represents their relation to other elements

Relations: Parents, Childrens, Siblings, ancestors, and descendants

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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
13
Q

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

getElementsByClassName();

getElementsByTagName();

querySelectorAll();

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

Why might you want to assign the return value of a DOM query to a variable?

A

When you need to work with the element more than once, you should use a variable to store the result of this query

var eleId = getElementByID(‘One’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
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
16
Q

Why would a 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 can access them.

17
Q

What does document.querySelector() take as its argument and what does it return?

A

It takes the first CSS Selector and returns the first matching element

18
Q

What does document.querySelectorAll() take as its argument and what does it return?

A

Uses a CSS Selector to select all matching elements/id/class

It returns the element

19
Q

Why do we log things to the console?

A

To test and communicate with our code to see if it’s working as intended

Debugging and double checking your value

20
Q

What is the purpose of events and event handling?

A

This enables the webpage to interact with it’s users

21
Q

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

A

It means that the arguments are optional

22
Q

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

element.addEventListener(‘eventName’, functionToRun);

23
Q

What is a callback function?

A

A function passed into another function as an argument

24
Q

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

A

The event object which contains all information about that event

25
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 is a reference to the object of which the event was dispatched

You google What is event.target mdn

26
Q

What is the difference between these two snippets of code?

A

element.addEventListener(‘click’, handleClick);

You’re calling the function with no extra arguments

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

You’re calling the function with extra arguments

Avoid this