Dom Flashcards

1
Q

Why do we log things to the console?

A

To debug

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

What is a “model”?

A

In this case, it’s the DOM tree displayed in a pattern or representation

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 “object” referring to in the phrase Document Object Model?

A

data type

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

Give two examples of document methods that retrieve a single element from the DOM?

A

getElementbyId(‘id’) and querySelector(‘css selector’)

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

Give one example of a document method that retrieves multiple elements from DOM at once.

A

querySelectorAll(‘css selector’)

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

Why might you want to assign the return value of a DOM query to a variable?

A

easier find and access

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

Why would a tag need to be placed at the bottom of the HTML content instead of at the top?

A

The browser needs to parse all of the elements of the HTML page before the Javascript code can access them. Simply because HTML needs to load before the script.

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

What does document.querySelector() take as its argument and what does it return?

A

Uses CSS selector syntax that would select one or more elements. This method returns only the first of the matching elements.

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

What does document.quertySelectorAll() take as its argument and what does it return?

A

Uses a CSS selector syntax to select one or more elements and returns all of those that match (returns a node list)

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

What is a DOM Tree?

A

model for a family tree containing its attributes and values as well

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

So that we get a reaction and execute it

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

JavaScript function definitions do not specify data types for parameters. JavaScript functions do not perform type checking on the passed arguments. JavaScript functions do not check the number of arguments received.

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

gets called back into calling scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
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 where the event happens, console.log to check

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

What is the className property of element objects?

A

dom method used to apply the className to a element object

19
Q

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

A

assign a new value to the property,

20
Q

what is the textContent property of element objects?

A

allows to manipulate text context, text.content property can also allow you to view the contents of the text.content property

21
Q

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

A

assigned a new value

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

harder, variables help organize and easier to debug/call

24
Q

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

A

easier to access or find

25
Q

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

A

no, it still needs to be added into the DOM tree

26
Q

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

A

appendChild

27
Q

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

A

name of attribute , value

28
Q

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

A

document.createElement() and appendChild()

29
Q

What is the textContent property of an element object for?

A

to add textContent

30
Q

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

A

className property, setAttribute

31
Q

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

A

ready made tool to re-use to add things in, much easier to test

32
Q

What is the event.target?

A

event where element occurs

33
Q

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

A

bubbling

34
Q

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

traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor

36
Q

How can you remove an element from the DOM?

A

.remove() method

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

attach them to parent

38
Q

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

A

hides element from viewport and makes it take no space

39
Q

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

A

takes the string of a css selector and returns a boolean

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

when you need to evaluate a value, every step is shown

42
Q

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

A

you would have to type everything out and not be able to reuse

43
Q

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

A

a huge chunk of if-else statements

44
Q

What is the event.target?

A

holds the target that triggers the event