DOM Flashcards

1
Q

Why do we log things to the console?

A

To check if the output is what we expected

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

What is a “model”?

A

A recreation of the original.

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

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

A

The 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

Dom node plus all of the elements that make it up.

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

To reuse the result.

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

So that the contents can load top to bottom first.

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

A string of CSS Selector and takes the first element that matches in the document.

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

String of CSS Selector and returns all elements that match the selector in the node list.

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 check our output

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

To add user functionality to the webpage.

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()

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

What is a callback function?

A

A function passed into another function as an argument.

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

Target is the place the element that we are dealing with originated from.

20
Q

What is the textContent property of element objects?

A

Adjust the text within an element

21
Q

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

A

Assign new text content to the dom object.

22
Q

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

A

No.

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

24
Q

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

A

To make re-usable variables.

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

element.appendChild(achild)

27
Q

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

A

Name, Value.

28
Q

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

A

Create the element, create text node, append child

29
Q

What is the textContent property of an element object for?

A

Adding text content

30
Q

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

A

setAttribute, className

31
Q

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

A

Repeating behavior and using the function multiple times.

32
Q

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

The event is carried through each layer of its ancestors.

33
Q

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

A

tagName.

34
Q

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

A

takes a css selector and returns dom element that is closest one.

35
Q

How can you remove an element from the DOM?

A

domelement.remove()

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

Add event to one layer higher than targeted element.

37
Q

What is the event.target?

A

Dom element object where the event originated

38
Q

What is the affect of setting an element to display: none?

A

Removes element from document flow (hides)

39
Q

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

A

takes a string of a css selector as an argument and returns a boolean value.

40
Q

How can you retrieve the value of an element’s attribute?

A

getAttribute()

41
Q

At what steps of the solution would it be helpful to log things to the console?

A

Every step.

42
Q

If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?

A

Make new event listener for every view.

43
Q

If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

A

Use a lot of if statements and loops.