DOMS Flashcards

1
Q

What is a “model”?

A

a representation of an actual thing

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

Which “document” is being referred to in the phrase Document Object Model?

A

a model of the HTML document that gets loaded to the browser as a javascript object

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

What is the word “object” referring to in the phrase Document Object Model?

A

each html element node. Has its own methods and properites and can be identified with element name id/class

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

What is a DOM Tree?

A

the tree comprised of nodes with html elements and its classes

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

Give two examples of document methods that retrieve a single element from the DOM.

A

document. querySelector() –> use this one

document. getElementByID()

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

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

document. ->

getElementsByClassName()
getElementsByTagName()
querySelectorAll() –> use this one

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

Why might you want to assign the return value of a DOM query to a variable?

A

to recall it later

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

Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?

A

the browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.

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

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

A

querySelector() -> string class, id, element but only returns the first match -> only returns one
querySelectorAll() -> css selector -> returns all that match

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

What is the purpose of events and event handling?

A

Events are actions or occurrences that happen in the system you are programming, which the system tells you about so your code can react to them.

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

What is a callback function?

A

function that is put as an argument

runFunction(function)

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

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

A

an event listener

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
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 DOM object that is listening for the event listener that is specified

17
Q

What is the difference between these two snippets of code?

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

A

first one, the function occurs when the add event listener is initiated but second one the handle click is being called immediately bc of the parentheses.

18
Q

What is the className property of element objects?

A
changes class name property that is seen in html class= '' 
<p class="blue"> Text </p>
p.className = 'red';

<p> Text </p>

19
Q

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

A

change class name using .className

20
Q

What is the textContent property of element objects?

A

gets the text of the specified dom object

21
Q

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

A

$var.textContent = ‘change text’;

22
Q

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

A

yes, that is how you initialize the event handling

23
Q

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

A

no, just stores a queried object into a variable. it does not add until you append it

24
Q

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

A

parent.appendChild( child )

.append( ) allows multiple elemnts to pass all at once

25
Q

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

A

.setAttribute( ‘ attribute ‘, ‘ name of attribute ‘)

26
Q

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

A

create element - > .createElement( ‘ element ‘ )

parent.appendChild( ^^)

27
Q

What is the textContent property of an element object for?

A

gives or updates value of textcontent

28
Q

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

A

.setAttribute( )
.className( )
.classList( )

29
Q

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

A

you can reuse that function

cleans up code?

30
Q

What is the event.target?

A

the location of which element an event occured in the query that you specified

so if queried div with bunch of buttons your event type can be in those buttons or labels or whatever

31
Q

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

A

because it is within the query that eventlistener is listening into –> within the breadth of listen

32
Q

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

A

event.target.tagName

33
Q

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

A

a css selector and returns the closest applicable one going towards document root so inside to outside.

34
Q

How can you remove an element from the DOM?

A

queriedElement.remove( );

35
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

just add eventListener to the parent element where you are putting that element and specify that you want the event.target to be that new element.