DOM Flashcards
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 from the DOM at once.
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 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.
What does document.querySelector() take as its argument and what does it return?
Selectors, and it returns an HTML element object representing the first element in the document that matches the specified set of CSS selectors, or null is returned if it doesn’t find a match.
What does document.querySelectorAll() take as its argument and what does it return?
Selectors and it returns a nodelist or an empty nodelist if it doesn’t find any matches.
What method of element objects lets u set up a function to be called when a specific type of event occurs?
the eventTarget.addeventListener();
What is a callback function
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.
what is the object 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 first waits for the event to happen then fires the function and the second one fires the event when the page gets loaded.
what do [ ] square brackets mean in function and method syntax documentation?
optional parameters
Does the document.createElement() method insert a new element into the page?
No it just creates an element
How do you add an element as a child to another element?
appendChild() method