Dom manipulation Flashcards
Why do we log things to the console?
To check them
What is a “model”?
a version of the page in memory structured to be a DOM tree
Which “document” is being referred to in the phrase Document Object Model?
the web page / the tree structure for the web page
What is the word “object” referring to in the phrase Document Object Model?
all HTML tags make up the DOM tree as it sees tags as objects / all elements that go into the DOM tree
What is a DOM Tree?
it is made up of all the HTML tags / how the DOM structures the model of the web page / kinda like an organization chart CEO at top and alot of workers at the bottom
Give two examples of document methods that retrieve a single element from the DOM.
querySelector / getElementById
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?
so it doesn’t have to be searched for every time you want to use it.
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 all the HTML loads before it
What does document.querySelector() take as its argument and what does it return?
takes a string or css selector / returns the first matching element
What does document.querySelectorAll() take as its argument and what does it return?
takes a string or css selector / returns all the matching elements as a NodeList
Why do we log things to the console?
to check them
What is the purpose of events and event handling?
so we know what the user is doing and how to handle it
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
What is a callback function?
function passed into another function as an argument
What object is passed into an event listener callback when the event fires?
event object
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
check by using console.log / console.dir / or mdn
reference to the object onto which the event was dispatched.
element that is being interacted with
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
the bottom code calls the function as soon as it loads instead of by the user or when the event is triggered
What is the className property of element objects?
className is the attribute for the element
How do you update the CSS class attribute of an element using JavaScript?
with the className property and the assignment operator / without = you would just get a list and can log it
What is the textContent property of element objects?
The textContent property allows you to
collect or update just the text that is in the
containing element (and its children).
How do you update the text within an element using JavaScript?
by changing the textContent property of an element