DOM Flashcards
Why do we log things to the console?
Things are logged to the console for testing and tracking values when running a program.
What is a “model”?
A “model” is a recreation of 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 JavaScript object data type. (JavaScript Objects)
What is a DOM Tree?
The DOM Tree is a model of web page that consists of four types of nodes: document, element, attribute, and text nodes.
Give two examples of document methods that retrieve a single element from the DOM.
document.querySelector();
document.getElementByID();
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.getElementsByTagName();
document.querySelectorAll();
Why might you want to assign the return value of a DOM query to a variable?
You may need to work with the query more than once.
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?
So the content of the web page can be loaded first.
What does document.querySelector() take as its argument and what does it return?
A string representing the CSS selector. It returns the first element that matches the selector.
What does document.querySelectorAll() take as its argument and what does it return?
A string representing the CSS selector. It returns a node list of matching elements.
Why do we log things to the console?
Things are logged to the console for testing and tracking values when running a program.
What is the purpose of events and event handling?
Events notify the program of any changes that may affect the code. Event handling takes place when an event takes place.
Are all possible parameters required to use a JavaScript method or function?
No. Many are optional.
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 which is invoked inside the outer function.
What object is passed into an event listener callback when the event fires?
The event object which contains all the data about the event.
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 whatever element the event occurred at.
Log the event.target to the console.
MDN.
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
The first snippet passes the callback function as a parameter to the method.
The second snipped passes the return of the function as a parameter to the method.
What is the className property of element objects?
The className property gets the or sets the value of the class attribute in the element.
How do you update the CSS class attribute of an element using JavaScript?
By assigning the new value to the className property of the element object.