DOM Flashcards

1
Q

Why do we log things to the console?

A

to check and see if our 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

the structure of a web page.

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

Data type object that can hold multiple values.

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 page. JavaScript object model of the html document. not the original, representation of the original. DOM is not html doc. JavaScript object recreating html document. javascript object for html element, including all of its attributes values and children’s attributes and values..

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

getElementsByClassName, getElementsByTagName, 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

so that you can access it and reuse it later.

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

you need the html document to load first before JavaScript does.

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 string that contains css selector as argument and returns the first of the matching elements.

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 string that contains css selector as argument and returns all of the elements that match as NodeList.

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 work and see if the output is the result anticipated.

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

events occur based on user interaction and makes website more interactive. Event handlers specify the type of user interaction. create a reaction, do that reaction in response to something happening. for interactivity in web applications.

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. for instance, the splice method does not require new items to add in.

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 of element objects.

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

What is a callback function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. the code that you want it to run when the event fires. function definition being passes around as a value. there will never be a return value for a callback function.

18
Q

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

A

object with a huge amount of properties that contain all the data describing that event.

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

The target property of the Event interface is a reference to the object onto which the event was dispatched. Where the event occurred. element where the event occurred.

20
Q

What is the difference between these two snippets of code?

A

One is a regular function calling expression, other is a callback function. In callback functions, parenthesis is omitted to indicate that the function should run as the page loads rather than when the event fires. one is passing function as an argument, other is assigning return value of a function.

21
Q

What is the className property of element objects?

A

sets the value of the class attribute of the specified element. property that hold value of class attribute for html element, and you can get that value or set that value.

22
Q

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

A

using className property and assigning new class name.

23
Q

What is the textContent property of element objects?

A

represents the text content of the node and its descendants.

24
Q

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

A

using textContent property and assigning new text content.

25
Q

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

A

no. you dont always need to know where the event happened. event object are very verbose, but not a guarantee that you need all the info. always have event parameter for call back functions to know that function is a event call back function

26
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

complicated

27
Q

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

A

because you can use it or modify it later. dont mix up html with javascript.

28
Q

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

A

no, just creates it

29
Q

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

A

appendChild method, append. append can receive multiple arguments, appendChild does not.

30
Q

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

A

attribute name, and the value for that attribute, in parenthesis.

31
Q

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

A

createElement, store new element, query for parent element, call appendChild on the parent with the new created element as an argument.

32
Q

What is the textContent property of an element object for?

A

represents the text content of the node and its descendants. retrieve text content or update text content if necessary.

33
Q

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

A

className property and setattribute method.

34
Q

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

A

you can call that function whenever you need that DOM Tree, you can pass in a parameter, which can be useful when structuring a DOM Tree. Give that function a name that clearly states what it does. easier to test.

35
Q

What is the event.target?

A

target property of event object, in which it shows the element where an event happened.

36
Q

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

A

because of event bubbling. if event occurs on one element, it also occurs on its parent elements.

37
Q

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

A

tagName property

38
Q

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

A

takes css selector as argument and returns matching ancestor.

39
Q

How can you remove an element from the DOM?

A

remove method.

40
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 the event listener on the parent of all those elements. you need to check if the event.target is the right place you want it to be.