DOM Flashcards
Why do we log things to the console?
To check functionality or accuracy of code
What is a “model”?
A representation of something
Which “document” is being referred to in the phrase Document Object Model?
The HTML page or document object
What is the word “object” referring to in the phrase Document Object Model?
Each different part of the page
What is a DOM Tree?
A DOM tree, which is made of the document node, element nodes, attribute nodes and text nodes; or all the HTML elements that make up the page
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.
getElementsByClassName(), getElementsByTagName(), querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
If you need to work with an element more than once
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
The HTML elements need to be processed before Javascript can access them
What does document.querySelector() take as its argument and what does it return?
Uses a CSS selector 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
What is the purpose of events and event handling?
To listen and respond to user interactions
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 being passed through another function as an argument
What object is passed into an event listener callback when the event fires?
The event object
What is the event.target?
A property of the event object that represents the HTML element that was interacted with and where the event is being dispatched.
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
Having () after a function name will call it regardless of whether there is an event and that returned result is being used in the addEventListener method
What is the className property of element objects?
A property of the Element interface that retrieves or sets the class of the specified element