DOM Flashcards
(39 cards)
Why do we log things to the console?
For debugging and an easy way to inspect your variables in the browser
What is a “model”?
Replica
Which “document” is being referred to in the phrase Document Object Model?
The HTML
What is the word “object” referring to in the phrase Document Object Model?
JavaScript object
What is a DOM Tree?
DOM element and all of the items in it
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?
For reusability and accessibility
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 run the html document first in order to create a DOM
What does document.querySelector() take as its argument and what does it return?
CSS selector and it returns the first element from the document
What does document.querySelectorAll() take as its argument and what does it return?
CSS selector and it returns NodeList of all elements matching the selector
What is the purpose of events and event handling?
Events are actions or occurrences that happen in the system
Event handling is steps to trigger some JavaScript code
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?
An object with all of the possible data the browser can provide
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
The target property of the Event interface is a reference to the object onto which the event was dispatched
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
In the first snippet, the event listener will call on the handleClick function only when the event occurs
In the second snippet, the event listener is calling on the handleClick function but that immediately calls the function
What is the className property of element objects?
Gets and sets the value of the class attribute of the specified element.
How do you update the CSS class attribute of an element using JavaScript?
Assign a string with new property name to the className property of element object
What is the textContent property of element objects?
Represents the text content of the node and its descendants.
How do you update the text within an element using JavaScript?
Assign a string with new text to the textContent property of element object
Is the event parameter of an event listener callback always useful?
No