DOM Flashcards

1
Q

why do we log things to the console?

A

during development, keep track of results

check functionality and data verification

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

what is a “model?”

A

a system or thing used as an example to follow or imitate

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

JavaScript objects

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 a web page consisting of all elements and their nodes

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(‘id’)

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

querySelectorAll(‘css selector’)

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

variable stores a reference to the object in the dom tree

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

browser needs to parse all of the elements in the HTML before javascript code can access them

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

takes elements within the document that matches the specified selector, or gorup of selectors

returns an HTMLelement object representing the first element in the document that matches the CSS seleector, or null is returned if there is no match

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

takes CSS selector as argument

rreturns a static NodeList representing a list of the document’s elements that match the specified group of selectors

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

keep track of data
functionality
data verification

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

keep track of how the user interacts with the web page

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

what do [] square brackets mean in function and method syntax documentation?

A

brackets are optional arguments

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 function to be used at some point in the future

18
Q

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

A

event 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

target property of the event is a reference to the object/element onto which the event was dispatched

check MDN

20
Q

what is the difference between these two snippets of code?

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

A

element.addEventListener(‘click’, handleClick)

code will not run until the vent fires

element.addEventListener(‘click’, handleClick())
code will run immediately as page loads

21
Q

what is the className property of element objects?

A

gets and sets the value of the class attribute of the specified element

22
Q

how do you update the CSS class attribute of an element using JS?

A

elemetNodeReference.className = cName;

23
Q

what is the textContent Property of element objects?

A

represents the text content of the node and its descendants

24
Q

how do you update the text within an element using JS?

A

someNode.textContent = string;

25
Q

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

A

no, it doens’t always make use of the event target

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 since variables are easier to access

27
Q

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

A

variables are easier to keep track of as the DOM can provide a lot of extra information

28
Q

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

A

no, it only creates the element node

29
Q

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

A

element.appendChild()

30
Q

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

A

.setAttribute(name, value)

31
Q

what steps do you need to take in order to insert a new eelement into the page?

A

createElement()
creatTextNode()/setAttribute()
appendChild()

32
Q

what is the textContent property of an element object for?

A

property of the nod interface represents the text content of the node and tis descendants

get/set textContent

33
Q

name two ways to set the class attribute of a DOM element

A

.setAttribute(‘class’, ‘className’)

element.className = ‘cName’

34
Q

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

A

reuability

save time

35
Q

what is the event.target?

A

reference to the object onto which the event fired

36
Q

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

A

event bubbling - starts at the most specific node and flows outward to the least specific one

37
Q

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

A

.tagName property

38
Q

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

A

takes CSS selector as argument and returns closest ancestor of the selected element

39
Q

how can you remove an element from the DOM?

A

node.remove() method

40
Q

if you wanted to insert new clickable DOM elements into the page using JS, how could you avoid adding an event listener to every new element individually?

A

dom-event-delgation

add a click event listener to the parent element and ensure the target is what you actually want to reference