DOM Flashcards

1
Q

Why do we log things to the console?

A

To check if the value given was as expected.

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.

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 data type object in javascript.

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

What is a DOM Tree?

A

JS Object for an html element including all of its children plus attributes and values for itself and its children.

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 and 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

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 use the same element more than once.

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 script tag need to be placed at the bottom of the HTML content instead of at the top?

A

So the browser can parse all of the elements in the page before the javascript code can access them.

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

Takes a CSS selector as an argument and returns the first element within the document that matches the 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

Takes a CSS selector as an argument and returns a static NodeList representing the documents elements that match the selector.

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 if the value given was as expected.

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 create a reaction for when something occurs on a webpage.

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

addEventListener( )

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

What is a callback function?

A

A function that is passed into another function as an argument.

17
Q

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

A

Object with properties that contain all of the data of the event that occurred.

18
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 object onto which the event occurred. Console log / MDN.

19
Q

What is the className property of element objects?

A

Gets and sets the value of the class attribute of the element.

20
Q

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

A

element.className = ‘ ‘.

21
Q

What is the textContent property of element objects?

A

Allows us to get or set text content of an element.

22
Q

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

A

node.textContent = ‘ ‘

23
Q

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

A

no

24
Q

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

A

To reuse the data and to not mix HTML with Javascript code.

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

appendChild( )

27
Q

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

A

DOMstring for the attribute.

28
Q

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

A

createElement, store element, query the parent element, and appendChild on parent with new element as an argument.

29
Q

What is the textContent property of an element object for?

A

gets and sets the text content of an element.

30
Q

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

A

className, and setAttrribute.

31
Q

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

A

To create something multiple times without writing the code again. Give the. code a name by. defining it in a function.

32
Q

What is the event.target?

A

The element where the event occurred.

33
Q

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

A

event bubbling

34
Q

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

A

tagName

35
Q

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

A

Takes a CSS selector as an argument and returns the closest matching element.

36
Q

How can you remove an element from the DOM?

A

.remove( )

37
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 listener to parent element.