DOM Flashcards
(44 cards)
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.
What object is passed into an event listener callback when the event fires?
it is the object created by the JS engine and relays all the information about the object
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
it is the read-on property target of the object event. You could check the console. Go onto MDN. Where the event occurred (started).
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
First, the second argument is a callback function. Second, the second argument is the return of the function is being called, which makes the function work. We cannot pass the work as an argument.
What is the className property of element objects?
The className property of the Element interface gets and sets the value of the class attribute of the specified element. Format is a string and the this needs to be the full string.
How do you update the CSS class attribute of an element using JavaScript?
using the property.className = “and new value of that property.
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?
by using the text.Content property