DOM Flashcards
Why do we log things to the console?
To be aware of what our code Is doing and to make sure it has the outcome we want
What is a “model”?
A replication of a dom tree that is stored in the browser’s terminal
Which “document” is being referred to in the phrase Document Object Model?
the HTML document we are working on
What is the word “object” referring to in the phrase Document Object Model?
Each object refers to a different part of the page in the browser
What is a DOM Tree?
Collection of all the objects that make up the document
Give two examples of document methods that retrieve a single element from the DOM.
Document.getElementById() & document.querySelector()
Give one example of a document method that retrieves multiple elements from the DOM at once.
Document.querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
If you know that you need to call on that query multiple times
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 it can run the entire body to map out a tree before running our script
What does document.querySelector() take as its argument and what does it return?
Takes our class or id as an argument and returns the first instance of it
What does document.querySelectorAll() take as its argument and what does it return?
Takes all the elements or class we are looking for and returns a nodes list
What are some differences of Nodes list and HTML collection?
o Html collection will live update as you add things
o Nodes list is static and would not update
What is the purpose of events and event handling?
Events will trigger code. Event handling is to run blocks of code based on what happens on our webpage
What method of element objects let 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 then invoked inside the outer function to complete some kind of action
What object is passed into an event listener callback when the event fires?
The event object. It gives us information about the event that actually occurs
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
The specific html element that was interacted with and that caused it to occur
What is the difference between these two snippets of code? element.addEventListener(‘click, handleClick) & element.addEventListener(‘click’, handleClick())
a function without the parenthesis is a reference to the function. With parenthesis you are actually calling it.
What is the className property of element objects?
the current classes on the object and allows us to dynamically update it
How do you update the CSS class attribute of an element using Javascript?
By using .className = and then the name you want to change it to
What is the textContent property of element objects?
It represents the text content of the node and its descendants
How do you update the text within an element using JavaScript?
Calling that element.textContent = the new value you want to assign to that element
Is the event parameter of an event listener callback always useful?
It is useful but sometimes you do not need it, sometimes it is useful to know what the function is expecting in its parameter though