Document Object Model Flashcards

1
Q

Why doe we log things to the console?

A

To debug our code and make sure it works

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

What is a “model”?

A

a representation of the HTML page in tree form

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 but we’re working with the byproduct of the 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

Each object represents a different part of the page loaded in the browser

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 the page when it loads in a browser in the form of 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

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

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

Its easier to find if the browser needs to use the same elements more than once.

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

So it can create a model after the document since the browser reads it from top to bottom

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

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

A

it takes in a css selector or and returns a HTML element object representing the first element in the document that matches the specified set of CSS selectors or null if there are no mtaches

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

selectors and it returns a nodelist containing one element object for each element that matches at least one specific selector or an empty nodelist if none match.

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

Events trigger functions in javascript code and event handling is the steps it takes for events to trigger the code

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

what method of element objects lets you set up a function to be called when a specific type of event occurs?

A

The eventTarget.addEventListener();

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

What is a call back function?

A

a function passed into another function as an argument, which is the invoked inside the outer function to complete some kind of action or routine

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

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

A

the event object

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

The target property of the event interface which references the object onto which the event was dispatched. console.log MDN

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

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

A

The second one fires the event when the page gets loaded and the first waits for the event to happen then fires the function

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

What is the className property of element objects?

A

Property of the element interface that gets and sets the value of the class attribute of the specified element

21
Q

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

A

Add the property className

22
Q

What is the textContent property of element objects?

A

Represents the text content of the node and its descendants

23
Q

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

A

textContent property

24
Q

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

A

Not always useful but will always be present and you should always have it.

25
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

26
Q

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

A

If you wanna do work in JS not very intuitive to go to the HTML and bring it back to do something. We want everything in one spot.

27
Q

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

A

focus

28
Q

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

A

blur

29
Q

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

A

input

30
Q

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

A

submit event

31
Q

What does event.preventDeafault() method do?

A

prevents the browser from automatically reloading with the forms values in the URL/prevents default behavior of the form

32
Q

What does submitting a form without event.preventDefault do?

A

automatically loads the form values

33
Q

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

A

the element

34
Q

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

A

the value property

35
Q

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

A

You don’t know if you ran into errors halfway through writing.

36
Q

what is the advantage of having your console open when writing a javascript program?

A

To test your code to make sure its working.

37
Q

What is the event.target

A

the target property of the event interface which is reference to the object onto which the event was dispatched

38
Q

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

A

Because of event bubbling

39
Q

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

A

element.tagName

40
Q

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

A

The selector and closestElement is the elemnt which is the closest ancestor of the selected element. It may be null.

41
Q

How can you remove an element from the DOM?

A

remove() method

42
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

By just targeting the parent element/put it on the element that holds the element.

43
Q

What is the event.target?

A

the target property of the event interface which is reference to the object onto which the event was dispatched.

44
Q

What does the element.matches method take as its arugment and what does it return.

A

Selector string, boolean

45
Q

At what steps of the solution would it be helpful to log things to the console?

A

every step

46
Q

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

A

we’d have to use an event listener for every element.

47
Q

if you didn’t use a loop to conditionally show or hide the views in the page, how woul dyour Javascript code be written instead?

A

You’d need to write a conditional for each view.

48
Q

How can you retrieve the value of an elements attribute?

A

getAttribute() method