DOM Flashcards
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 document object representing the HTML document.
What is a DOM Tree?
The tree structure formed by an element object and its descendants.
Give two examples of document methods that retrieve a single element from the DOM.
.getElementById() and .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?
To reuse the object and save time rather than having .querySelector() search the document every time we need it.
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why would a script tag need to placed at the bottom of the HTML content instead of the top?
Because all the elements need to be loaded first.
What does document.querySelector() take as its argument and what does it return?
Takes a CSS selector string and returns the first matching element object.
What does document.querySelectorAll() take as its argument and what does it return?
Takes a CSS selector string and returns a NodeList of all matching nodes.
What is the purpose of events and event handling?
Event handling lets us make our pages 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(event, function)
What is a callback function?
A function passed as an argument to another function.
What object is passed into an event listener callback when the event fires?
The argument given to the callback function is the event object.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
Which element the event originated from. You could log it out to check, and go on MDN to find more information.
What’s the difference between handleClick and handleClick()?
handleClick is interpreted as a variable where the function is being called with handleClick()
What’s the difference between an Event Listener and Event Handler?
The Event Listener checks for events on the element it’s bound to and you don’t directly interact with it. The Event Handler function is passed as an argument to the .addEventListener() function to execute a code block when the event occurs.
What is the className property of element objects?
The className property stores a value that corresponds to the class attribute of the HTML element it represents.
How do you update the HTML class attribute of an element using JavaScript?
Assign a new String of class name(s) to element.className
What is the textContent property of element objects?
The textContent property stores a value that corresponds to the text content present in an HTML element.