DOM 1 Flashcards

1
Q

Why do we log things to the console?

A

to see what’s going on in the code and help with debugging

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

What is a “model”?

A

replica. when 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
3
Q

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

A

HTML document.

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

javascript object.

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

What is a DOM Tree?

A

the way in which the browser should structure the model. (Model of a web page made of objects)

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

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

to save time and be able to access the variable multiple times.

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

Javascript is often used to manipulate DOM and add new functionality to the webpage. If tag is not added at end of the tag, DOM may not be ready by that time, thus preventing javascript to work on it, leading to unknown behaviors.

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

it takes CSS selector as parameter and returns the first element within the document that matches the specified 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

it takes CSS selector as parameter and returns non-live NodeList containing one element object for each element that matches at least one of the specified selectors or an empty NodeList in case no matches.

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 see what’s going on in the code and help with debugging

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

Event handlers can be used to handle and verify user input, user actions, and browser actions:

  • Things that should be done every time a page loads
  • Things that should be done when the page is closed
  • Action that should be performed when a user clicks a button
  • Content that should be verified when a user inputs data
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()

17
Q

What is a callback function?

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

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?

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 property or classList property

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 property or innerHTML property

24
Q

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

A

no

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

more complicated.

26
Q

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

A

makes the code unreliable when stored in DOM

27
Q

what is the difference between two codes?

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

A

in the first code, we are passing in handleclick function as call back function and in the second code, we are just calling the function handleClick; hence in the second code we are returning the result of the function value.