DOM Flashcards

1
Q

Why do we log things to the console?

A

To see easily and more directly the code whenever I check or fix it.

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

What is a “model”?

A

It contains interactive data

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.

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

It referring to the JavaScript language.

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

Give two examples of document methods that retrieve a single element from the DOM.

A

querySelector and getDocumentByID.

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

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

A

It reduces the computer’s work.

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

What console method allows you to inspect the properties of a DOM element object?

A

dir (directory).

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

Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?

A

Because of the source order.

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

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

A

It takes an element, class, id, etc’s name and it returns their values.

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

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

A

It takes an element, class, id, etc’s name and it returns all of their values under the same name tag.

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

What is the purpose of events and event handling?

A

To handle and verify inputs and actions (user input, user actions, and browser actions).

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

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

A

It’s optional. But the type and listener must be there.

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

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

A

EventTarget method addEventListener().

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

What is a callback function?

A

It’s a function passed to another function as an argument.

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

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

A

The first argument.

17
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. Ask MDN.

18
Q

What is the difference between these two snippets of code? element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())

A

The second code, handleClick with parentheses means that this function works right now.

19
Q

What is the className property of element objects?

A

It gets and sets the value of the class attribute of the specified element.

20
Q

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

A

Using the getAttribute method.

21
Q

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

A

object name.textContent.

22
Q

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

A

No, because the event listener is not always needed.

23
Q

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

A

Because it reduces the work if I set up the value of the thing to the variable.

24
Q

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

A

Because it reduces the work if I set up the value of the thing to the variable.

25
Q

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

A

No.

26
Q

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

A

Using the appendChild() method.

27
Q

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

A

Attribute, and value of that attribute.

28
Q

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

A

Create the element, choose the spot you want to insert the new element and use the appendChild() method to append it on there.

29
Q

What is the textContent property of an element object for?

A

Reading and writing.

30
Q

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

A

Use setAttribute() method or className as a property of the object.

31
Q

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

A

We can reuse rather than work again about to get that result, Dynamism.

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

33
Q

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

A

event.target

34
Q

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

A

The argument is a selector and it returns itself or its ancestor.

35
Q

How can you remove an element from the DOM?

A

Using the .remove() method.

36
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

Using event.delegation.