DOM Basics Flashcards
What is the DOM?
document object model - a representation/standardization
can access and change all elements of HTML document
What does
document.querySelector()
return?
returns first element that matches selector
returns null if no matches
How do you modify the text of elements on the DOM?
element.textContent = ‘insert text content here’
What arguments does the addEventListener method take?
event to listen to function to run when event occurs
Give five examples of JavaScript events that can be listened for.
click mousemove dblclick cut copy paste
What does document.createElement() take as its argument?
the element being created
What does document.createElement() return?
DOM element
JS object representing a DOM element
How do you append elements to the DOM?
newElement.appendChild(newContent);
Why do we log things to the console?
so we can see what is going on with our code. checkpoints
Why might you want to assign the return value of a DOM query to a variable?
so you can use it later
its faster because you don’t need to search the document for the items again
What console method allows you to inspect the properties of a DOM element object?
console.dir
What does document.querySelector( ) take as its argument and what does it return?
takes any valid CSS selector and will return the element by name, class or ID
What does document.querySelectorAll() take as its argument and what does it return?
can take any valid CSS selector
returns nodeList
Why would a [script] tag need to be placed at the bottom of the HTML content instead of at the top?
browser needs to parse / load to html – > DOM NEEDS TO LOAD
before js can access them
or else js will result in nulls
Is NodeList an array?
NodeList is NOT AN ARRAY
if you expand, a lot of the array methods are missing from list
are numerically indexed, have length property
thus you can loop through nodeLists
var name for DOM element
$heading
use a $
what is a callback function?
function that we give to another function (we do not call it, we pass it to another function)
What is the purpose of events and event handling?
to handle user input, user actions, and browser actions
Are all possible parameters required to use a JavaScript method or function?
no