DOM Flashcards

(46 cards)

1
Q

Why do we log things to the console?

A

For debugging and/or making sure things work

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

What is a “model”?

A

Layout of the html document as a tree of objects

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

HTML elements as objects

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

What is a DOM Tree?

A

The HTML document in the form of a model of objects that looks like a tree

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

document.queryselector()
document.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

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

So you can access 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

 tag need to be placed at the bottom of the HTML content instead of at the top?
A

If it was at the top, the website would stop loading until all of the javascript was downloaded

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

CSS selector as argument
Returns an element object representing the first element in 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

CSS selector as argument
Returns a NodeList containing one element object for each element that matches the selector

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

Handler is called by listener (I write handler)

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

No

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

Event listener

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

What is a callback function?

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

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

A

event

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

Returns the element that triggered the event

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

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

20
Q

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

21
Q

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

22
Q

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

23
Q

What does the event.preventDefault() method do?

A

Prevents default behavior of the event

24
Q

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

A

refreshes the page

25
What property of a form element object contains all of the form's controls.
form.elements
26
What property of a form control object gets and sets its value?
value property
27
What is one risk of writing a lot of code without checking to see if it works so far?
Bugs/errors
28
What is an advantage of having your console open when writing a JavaScript program?
To check for bugs/errors
29
Does the document.createElement() method insert a new element into the page?
It doesn't until it is appended
30
How do you add an element as a child to another element?
document.appendChild()
31
What do you pass as the arguments to the element.setAttribute() method?
Name of the attribute, value
32
What steps do you need to take in order to insert a new element into the page?
createElement -> append
33
What is the textContent property of an element object for?
The text for the element
34
Name two ways to set the class attribute of a DOM element.
classname or setAttribute or classList
35
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
You can create it for multiple items at once, and since it's a function it will be there for later use?
36
What is the event.target?
It's what element the user interacted with
37
Why is it possible to listen for events on one element that actually happen its descendent elements?
Bubbling
38
What DOM element property tells you what type of element it is?
event.target.tagName
39
What does the element.closest() method take as its argument and what does it return?
Css selector and returns the closest upward element or parent selected
40
How can you remove an element from the DOM?
remove()
41
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?
Adding an event listener to the parent element
42
What is the affect of setting an element to display: none?
Removed from page
43
What does the element.matches() method take as an argument and what does it return?
make sure an element has a css selector
44
How can you retrieve the value of an element's attribute?
.getAttribute()
45
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?
Separate event handlers for each event listener
46
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?
Individual conditionals