JS DOM Flashcards
Why do we log things to the console?
to see the data
What is a “model”?
a representation of something
Which “document” is being referred to in the phrase Document Object Model?
HTML document
What is the word “object” referring to in the phrase Document Object Model?
the model is made up of nodes, which are javascript objects
What is a DOM Tree?
a model of a web page made up of 4 types of nodes
Give two examples of document methods that retrieve a single element from the DOM.
getElementById(), querySelector()
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?
to access the DOM element later in the code to manipulate it
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why would a JavaScript tag need to be placed at the bottom of the HTML content instead of at the top?
to allow all the HTML elements to load, before doing anything to them
What does document.querySelector() take as its argument and what does it return?
- argument is a css selector type
- returns object of first element within the document that matches
What does document.querySelectorAll() take as its argument and what does it return?
- argument is one or more selector types
- returns nodelist of elements within the document that matches group of selectors
What is the purpose of events and event handling?
events allow for triggering code based on conditions
What do [] square brackets mean in function and method syntax documentation?
optional
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 function which is an argument of another function
What object is passed into an event listener callback when the event fires?
event object
What is the event.target?
target is a property which references the element which triggered the event
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
- the first method runs on ‘click’
- the second method gets the return value of undefined
What is the className property of element objects?
a string containing value of class attribute, which allows you to assign a css class to an element