Document Object Model (DOM) Flashcards

1
Q

Why do we log things to the console?

A
  • To verify and check code.
  • To use for bug checking.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a “model”?

A
  • A representation of something, but not the real thing.
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
  • The html document.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which “objects” are being referred to in the phrase Document Object Model?

A
  • The data type objects within the JavaScript language.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a DOM Tree?

A
  • A model of a web page.
  • A model of a portion of a webpage.
  • (An element plus all of its content and configurations).
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
  • querySelector(). (Always just use this for selecting a single element query).
  • getElementByID(). (Old, not really needed anymore).
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(). (Always just use this for selecting multiple element queries.
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 reuse it later.
  • Cut down on amount of code.
  • Cleans up code.
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 query to a variable?

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
  • Gives the HTML time to load before any of the JavaScript loads, which can prevent errors, and can speed up website response time.
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 a string (a CSS selector) as its argument, and it returns THE FIRST element that matches the CSS selector (which is an object).
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 a string as its argument, and returns a NodeList.
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
  • Interactivity. The developer can prepare for actions taken by users and create a response.
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
  • No, not necessary at all times.
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
  • add.eventListener.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a callback function?

A
  • Taking a function and passing it around.
  • Ex. sharing a recipe with a friend.
17
Q

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

A
  • Information about what happened with the event.
18
Q

What is the event.target? If you weren’t sure, how would you check? where could you get more info about it?

A
  • The element that triggers the event.
  • Console.log.
  • MDN
19
Q

What is the difference between these two snippets of code?

A

element.addEventListener(‘click’, handleClick):
- This is passing a variable in as the function.

element.addEventListener(‘click’, handleClick()):
- This is calling the function inside the event listener method.
(DO NOT DO THIS)