DOM Flashcards
Why do we log things to the console?
To verify and check code, and to use for investigating.
What is a “model”?
Something that represents something.
Which “document” is being referred to in the phrase Document Object Model?
The HTML document
What is the word “object” referring to in the phrase Document Object Model?
The data type object
What is a DOM Tree?
The way a browser makes a model and structures an html page.
An element plus all of it’s configuration information plus it’s children and their configuration information.
Give two examples of document methods that retrieve a single element from the DOM.
getElementById()
querySelector() <– use this almost always.
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?
To be able to reference it to use many times later.
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 too parse through all elements before javascript can access it.
What does document.querySelector() take as its argument and what does it return?
Uses a CSS selector (‘string’) and returns the first matching element.
What does document.querySelectorAll() take as its argument and what does it return?
Uses a CSS selector to select all matching elements returns the NodeList.
What is the purpose of events and event handling?
User interaction to make a response to an interaction. Interactivity
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 callback function is a function passed into another function as an argument.
What object is passed into an event listener callback when the event fires?
data about what happened.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
The event.target is the element on the html that the event originated from. Go to MDN for more information.
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick) <– passing a variable which will be called when the action happens.
element.addEventListener(‘click’, handleClick()) <– calling the function without the interaction. (It is wrong, do not use.)
What is the className property of element objects?
value of the attribute class on the html element.
How do you update the CSS class attribute of an element using JavaScript?
use the className property
What is the textContent property of element objects?
changes the text-content of the element it is attached to.