DOM Flashcards
Why do we log things to the console?
to keep a record of the output (self-check)
What is a “model”?
a representation of the the actual thing, recreation of something
Which “document” is being referred to in the phrase Document Object Model?
it would be the HTML document
What is the word “object” referring to in the phrase Document Object Model?
the data type (elements) from the HTML
What is a DOM Tree?
it is a layout like a family tree that consists of HTML elements and how they connect to each other. Body element with all of its child elements and the content it holds.
Give two examples of document methods that retrieve a single element from the DOM.
getElementById, querySelector(‘CSS selector’)
Give one example of a document method that retrieves multiple elements from the DOM at once.
getElementByClassName(‘class’),
Why might you want to assign the return value of a DOM query to a variable?
in the future for reference, it is much easier and efficient to assign it to a variable for faster access.
What console method allows you to inspect the properties of a DOM element object?
console.dir; the directory method of the console object.
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
the browser reads the code from top to bottom. In the JS when referring to elements (objects) there is nothing to refer to.
What does document.querySelector() take as its argument and what does it return?
it takes a string which is a CSS selector as arguments and returns the first element that matches the selector
What does document.querySelectorAll() take as its argument and what does it return?
it takes a selector as an argument and returns a list of properties of that object which is called a node list.
Why do we log things to the console?
to keep track of our output and see if our code at each code
What is the purpose of events and event handling?
it is for a function or action to be performed when and after a user interacts with the page itself.
Are all possible parameters required to use a JavaScript method or function?
No, not all the parameters are needed (boolean).
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, which is then invoked inside the outer function to complete some kind of routine or action.