DOM Flashcards

1
Q

Why do we log things to the console?

A

to keep a record of the output (self-check)

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 the actual thing, recreation of something

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

it would be 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

the data type (elements) from the HTML

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

What is a DOM Tree?

A

it is a layout like a family tree that consists of HTML elements and how they connect to each other. Body element with all of its child elements and the content it holds.

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

getElementById, querySelector(‘CSS selector’)

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

getElementByClassName(‘class’),

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

in the future for reference, it is much easier and efficient to assign it to a variable for faster access.

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; the directory method of the console object.

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

the browser reads the code from top to bottom. In the JS when referring to elements (objects) there is nothing to refer to.

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 which is a CSS selector as arguments and returns the first element 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

it takes a selector as an argument and returns a list of properties of that object which is called a node list.

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 keep track of our output and see if our code at each code

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

it is for a function or action to be performed when and after a user interacts with the page itself.

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, not all the parameters are needed (boolean).

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

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.

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

it is the object created by the JS engine and relays all the information about the object

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

it is the read-on property target of the object event. You could check the console. Go onto MDN. Where the event occurred (started).

20
Q

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())

A

First, the second argument is a callback function. Second, the second argument is the return of the function is being called, which makes the function work. We cannot pass the work as an argument.

21
Q

What is the className property of element objects?

A

The className property of the Element interface gets and sets the value of the class attribute of the specified element. Format is a string and the this needs to be the full string.

22
Q

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

A

using the property.className = “and new value of that property.

23
Q

What is the textContent property of element objects?

A

it represents the text content of the node and its descendants.

24
Q

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

A

by using the text.Content property

25
Q

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

A

not always useful

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 because wouldnt be able to keep track of the # of clicks, and would have to go back into the DOM to retrieve that element

27
Q

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

A

You are able to access it in the future. easy to update and visible.

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 ?

A

submit

32
Q

What does the event.preventDefault() method do?

A

stops the page from refreshing…The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.
checkbox example on MDN

33
Q

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

A

does not refresh the page.

34
Q

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

A

elements property which are input, button, textarea….

35
Q

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

A

.value

36
Q

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

A

ultimately there is a chance it wont work, so checking it helps you know what exactly does not work. try to use console.log!

37
Q

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

A

Being able to see if anything goes wrong with the code. being able to see if an error is about to happen when saving.

38
Q

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

A

no, it needs to be appended to the parent element first or the DOM tree

39
Q

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

A

.appendChild() to the parent element

40
Q

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

A

the keyword of the attribute and the value in strings

41
Q

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

A

document.createElement(‘element’) assigned to a new variable, then if need be a text create a new variable with the value being .createTextNode(), and then append that textNode to the element and then append that element to a parent element

42
Q

What is the textContent property of an element object for?

A

to add text to an element

43
Q

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

A

setAttribute() and the className

44
Q

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

A

you are able to adjust the format of the app, and we can reuse that function over and over again
and you can you that DOM tree in multiple applications