Document Object Model Flashcards
Why doe we log things to the console?
To debug our code and make sure it works
What is a “model”?
a representation of the HTML page in tree form
Which “document” is being referred to in the phrase Document Object Model
The HTML document but we’re working with the byproduct of the document
What is the word “object” referring to in the phrase Document Object Model
Each object represents a different part of the page loaded in the browser
What is a DOM Tree?
A model of the page when it loads in a browser in the form of a tree
Give two examples of document methods that retrieve a single element from the DOM
QuerySelector and getElementById
Give one example of a document method that retrieves multiple elements
querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
Its easier to find if the browser needs to use the same elements more than once.
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
So it can create a model after the document since the browser reads it from top to bottom
What does the document.querySelector() take as its argument and what does it return
it takes in a css selector or and returns a HTML element object representing the first element in the document that matches the specified set of CSS selectors or null if there are no mtaches
What does document.querySelectorAll() take as its argument and what does it return?
selectors and it returns a nodelist containing one element object for each element that matches at least one specific selector or an empty nodelist if none match.
What is the purpose of events and event handling?
Events trigger functions in javascript code and event handling is the steps it takes for events to trigger the code
what method of element objects lets you set up a function to be called when a specific type of event occurs?
The eventTarget.addEventListener();
What is a call back function?
a function passed into another function as an argument, which is the invoked inside the outer function to complete some kind of action or routine
What object is passed into an event listener callback when the event fires?
the event object
what is the event.target? if you weren’t sure, how would you check? Where could you get more information about it?
The target property of the event interface which references the object onto which the event was dispatched. console.log MDN
What is the difference between these two snippets of code? element.addEventListener(‘click’, handleClick) element.addEventListener(‘click’, handleClick())
The second one fires the event when the page gets loaded and the first waits for the event to happen then fires the function
Are all possible parameters required to use a JavaScript method or function?
no