DOM Flashcards

1
Q

Why do we log things to the console?

A

to check the result of element

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

What is a “model”?

A

representation of an actual 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

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

JavaScript

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

What is a DOM Tree?

A

tree data structure of HTML page

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 & 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 reuse the result again

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 dom element gets loaded before javascript try to get elements

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

selector element and result first match

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

selector element and result is all-match

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

to perform some action base on user action

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 the className property of element objects?

A

its use to get and update class name of element

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

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

A

get element using className

19
Q

What is the textContent property of element objects?

A

It can get or update the element text content

20
Q

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

A

using element.textContetent = value

21
Q

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

A

No

22
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

23
Q

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

A

to get specific element property multiple time and going through dom each time is not effective its better to store it to the variable

24
Q

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

A

no it does not

25
Q

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

A

parentName.appenchild(childName)

26
Q

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

A

name of the attribute

27
Q

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

A

createElement() put it into variable
createTextNode() to create text
appendChild where to put the element

28
Q

What is the textContent property of an element object for?

A

to get or add text content to the element

29
Q

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

A

set attribute and class name

30
Q

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

A

reuse the code

31
Q

What is the event.target?

A

its return where the event occure

32
Q

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

A

bcas it carried forward to its ancestors

33
Q

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

A

tagName property

34
Q

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

A

it take css selector and return the closest one

35
Q

How can you remove an element from the DOM?

A

remove() method on DOM element

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 it to one layer above and listen to that event

37
Q

What is the event.target?

A

shows where event was trigger

38
Q

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

A

remove from document flow

39
Q

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

A

boolean value

40
Q

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

A

getAttribute() method

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

then need to write event for each element

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

we have to write if condition for each node