DOM Flashcards
Why do we log things to the console?
to check if the code is working properly and giving the expected output
What is a “model”?
a representation of something
Which “document” is being referred to in the phrase Document Object Model?
the HTML page
What is the word “object” referring to in the phrase Document Object Model?
the nodes of the HTML elements, which are JS objects
What is a DOM Tree?
a model of the HTML page, composed of nodes
Give two examples of document methods that retrieve a single element from the DOM.
.getElementByID( ), .querySelector( )
Give one example of a document method that retrieves multiple elements from the DOM at once.
.querySelectorAll( )
Why might you want to assign the return value of a DOM query to a variable?
so you can use the variable when you need a specific element instead of querying it over and over
What console method allows you to inspect the properties of a DOM element object?
console.dir( )
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
the browser needs to parse through the HTML page before JS can access anything
What does document.querySelector( ) take as its argument and what does it return?
a string with a CSS selector, returns first element that matches
What does document.querySelectorAll( ) take as its argument and what does it return?
a string with a CSS selector, returns all elements that match
What is the purpose of events and event handling?
makes a page more interactive and dynamic
Are all possible parameters required to use a JavaScript method or function?
no
What method of element objects lets you set up a function to be called when a specific type of event occurs?
.addEventListener( )
What is a callback function?
a function passed into another function as an argument
What object is passed into an event listener callback when the event fires?
event, an object created by the browser
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
where the event originated from, console.log to check, more info from mdn
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick( ))
the second one will call the function as soon as the page loads
What is the className property of element objects?
it gets and sets the value of the class attribute of an element
How do you update the CSS class attribute of an element using JavaScript?
.className = ‘new-class’
What is the textContent property of element objects?
it represents the text content of the node and its descendants