DOM Flashcards
What is a “model”?
A representation of an object/something
Which “document” is being referred to in the phrase Document Object Model?
The HTML document for that web application
What is the word “object” referring to in the phrase Document Object Model?
The model created is made out of objects in the JavaScript language.
What is a DOM Tree?
Each branch of the tree ends in a node, and each node contains objects.
The Document Object Model (DOM) connects web pages to scripts or programming languages by representing the structure of a document in memory.
A model of the web page and stored in browsers’ memory. / Element and all its children, and any data in the folder??
Give two examples of ‘document’ methods that retrieve a single element from the DOM.
‘getElementById()’ and ‘querySelector()’
Give one example of a ‘document’ method that retrieves multiple elements from the DOM at once.
‘getElementsByClassName()’ or ‘getElementsByTagName()’ or ‘querySelectorAll()’
Why might you want to assign the return value of a DOM query to a variable?
Store location of element and don’t have to look for it again
So you can access and work on the same element node more than once.
What ‘console’ method allows you to inspect the properties of a DOM element object?
dir
‘console.dir()’
Why would a ‘script’ tag need to be placed at the bottom of the HTML content instead of at the top?
The elements need to load first and when try to access through javascript, the elements exist first
The browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.
What does ‘document.querySelector()’ take as its argument and what does it return?
Takes CSS selector as argument and returns the first matching element.
What does ‘document.querySelectorAll()’ take as its argument and what does it return?
Takes CSS selector as argument and returns a NodeList of all elements with argument.
What is the purpose of events and event handling?
Events are things that happen; event handlers are functions we provide, work that should happen when events happen; so developers can respond to visitors actions
What do [] square brackets mean in function and method syntax documentation?
Means 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 callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.