DOM Flashcards

1
Q

Why do we log things to the console?

A

for debugging or to know what you are working with

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

What is a “model”?

A

a representation or recreation of something that isn’t exact

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

data type object

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

What is a DOM Tree?

A

any element and holds all the configuration and the sum of all its parts

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

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

document.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 variable and not calling the query function every time you need to use it

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() or dir method

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

to load all the content

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

it takes a string element with css selector and matches it

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

it takes a string element with css selector and node lists (collection of nodes)

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 debug and to know what you are working with

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

something occurred and information gets sent out also for allowing users to interact with the web page

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(), has 2 argument the string containing the event and the second argument is the callback function

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

What is a callback function?

A

when you pass a function as a value to another function

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

an object with a huge list of properties to describe the event that just occurred

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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 element where the event occurred. log it out or mdn.

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

What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())

A

the first one calls the function as a call back, while the second one calls the function immediately and nothing gets returned

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

What is the className property of element objects?

A

the value of the class attribute (not a selector)

22
Q

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

A

setAttribute() method

23
Q

What is the textContent property of element objects?

A

element . textContent

24
Q

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

A

element name with dot notation textContent “=” new string or variable

25
Q

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

A

no, but most of the time it will be

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

more complicated cause then you would have to code each “click”

27
Q

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

A

then you can use the variable instead of querying the dom element everytime

28
Q

What event is fired when a user places their cursor in a form control?

A

focus()

29
Q

What event is fired when a user’s cursor leaves a form control?

A

blur()

30
Q

What event is fired as a user changes the value of a form control?

A

input

31
Q

What event is fired when a user clicks the “submit” button within a <form>?

A

submit event fires on the form element itself only

32
Q

What does the event.preventDefault() method do?

A

prevents default behavior

33
Q

What does submitting a form without event.preventDefault() do?

A

it allows the page to refresh and to submit the data to the same page

34
Q

What property of a form element object contains all of the form’s controls.

A

form.elements or the elements property

35
Q

What property of a form control object gets and sets its value?

A

the value property

36
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

you wont know what part is working or not working

37
Q

What is an advantage of having your console open when writing a JavaScript program?

A

you can see if there is an error

38
Q

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

A

No

39
Q

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

A

appendChild() method

40
Q

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

A

(name of the attribute in a string, new value)

41
Q

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

A

createElement() -> make configurations (add text and class)-> querySelect for parent ->
parent.appendChild().

42
Q

What is the textContent property of an element object for?

A

text content

43
Q

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

A

className or setAttribute()

44
Q

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

A

you dont have to create a dom tree over and over again as well as gives reusability

45
Q

What is the event.target?

A

the element that was clicked on or interacted with

46
Q

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

A

event bubbling to the top

47
Q

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

A

tag name property value all uppercase

48
Q

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

A

takes css selector as argument and returns the nearest parent element that matches with the css selector

49
Q

How can you remove an element from the DOM?

A

element.remove()

50
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