DOM Query Flashcards
Why do we log things in the console?
debugging purposes.
What is a “model”?
a copy of something.
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?
referring to the data type object in javascript.
What is a DOM tree?
is an element with all of its contents and objects represented in a dom tree.
Give two examples of document methods that retrieve a single element from the dom.
getElementById() and 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’re going to use it many times in your javascript.
What console method allows you to assign the return value of a DOM query to a variable?
console.dir()
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
so that when the webpage loads all the content of the web page has been loaded before the script.
What does document.querySelector() take as its argument and what does it return?
it takes a string element with css selectors and returns their values.
What does document.querySelectorAll() take as its argument and what does it return?
CSS selectors and it returns a NodeList
What is the purpose of events and event handling?
they’re listening for specific events or waiting. events are functions that “handle” the function that javascript is listening for.
Are all possible parameters required to use a Javascript method or function?
What method of element objects lets you set up a function to be called when a specific type of event occurs?
create .addEventListener, the string
What is a callback function?
a function which is to be executed after another function has finished execution.
What object is passed into an event listener callback when the event fires?
an object with a huge set of properties that set an event to occur.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
it’s the element where the listener occured. log it out and look where it is.
What is the difference between these two snippets of code?
the first one actually passes the event listener. it runs right then when you put into the function.
What is the className property of element objects?
How do you update the CSS class attribute of an element using JavaScript?
What is the textContent property of element objects?
it allows you to update the text that is contained in the element.
How do you update the text within an element using Javascript?
the variable.text content = ‘string’ + variable.
is the event parameter of an event listener callback always useful?
Why is storing information about a program in variables better than only storing it in the DOM?
Does the document.createElement() method insert a new element into the page?
How do you add an element as a child to another element?
What do you pass as the arguments to the element.setAttribute() method?
What steps do you need to take in order to insert a new element into the page?
What is the textContent property of an element object for?
to add text to an element.
Name two ways to set the class attribute of a DOM element.
className setAttribute()
What are the two advantages
What is the event.target?
Why is it possible to listen for events on one element that actually happen in its descendant elements?
bubbling
What DOM element property tells you what type of element it is?
tagName property. value has to be uppercase.
What does the element.closest() method take as its argument and what does it return?
takes the argument closest to string. and returns the closest ancestor matching with the css selector.
How can you remove an element from the DOM?
element.remove()
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
add an eventListener to the ancestor. it’s called event delegation.
What is the event.target?
element interacted with.
What is the affect of something an element to display: none?
makes it so that it’s not visible. it’s still present though.
What does the element.matches() method take as an argument and what does it return?
takes a css selector and returns a boolean whether or not it matches the selector.
How can you retrieve the value of an element’s attribute?
element.getAttribute()
At what steps of the solution would it be helpful to log things to the console?
every new line of code.
If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?
conditionals for each individual view.
If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
What is a breakpoint in responsive web design?