Dom Flashcards
(44 cards)
Why do we log things to the console?
To debug
What is a “model”?
In this case, it’s the DOM tree displayed in a pattern or representation
Which “document” is being referred to in the phrase Document Object Model?
HTML
What is the “object” referring to in the phrase Document Object Model?
data type
Give two examples of document methods that retrieve a single element from the DOM?
getElementbyId(‘id’) and querySelector(‘css selector’)
Give one example of a document method that retrieves multiple elements from DOM at once.
querySelectorAll(‘css selector’)
Why might you want to assign the return value of a DOM query to a variable?
easier find and access
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?
The browser needs to parse all of the elements of the HTML page before the Javascript code can access them. Simply because HTML needs to load before the script.
What does document.querySelector() take as its argument and what does it return?
Uses CSS selector syntax that would select one or more elements. This method returns only the first of the matching elements.
What does document.quertySelectorAll() take as its argument and what does it return?
Uses a CSS selector syntax to select one or more elements and returns all of those that match (returns a node list)
What is a DOM Tree?
model for a family tree containing its attributes and values as well
What is the purpose of events and event handling?
So that we get a reaction and execute it
Are all possible parameters required to use a JavaScript method or function?
JavaScript function definitions do not specify data types for parameters. JavaScript functions do not perform type checking on the passed arguments. JavaScript functions do not check the number of arguments received.
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?
gets called back into calling scope
What is the event.target? if you weren’t sure, how would you check? Where could you get more information about it.
target is where the event happens, console.log to check
What is the className property of element objects?
dom method used to apply the className to a element object
How do you update the CSS class attribute of an element using JS?
assign a new value to the property,
what is the textContent property of element objects?
allows to manipulate text context, text.content property can also allow you to view the contents of the text.content property
How do you update the text within an element using JavaScript?
assigned a new value
Is the event parameter of an event listener callback always useful?
no
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
harder, variables help organize and easier to debug/call
Why is storing information about a program in variables better than only storing it in the DOM?
easier to access or find