DOM Flashcards
only use?
querySelector(‘xxx’)
querySelectorAll(‘xxx’)
callback
share the value of one function with another
event handler
the function write for event (no return in here because only event will get the value, you will never call it by yourself)
What is a DOM Tree?
Which “document” is being referred to in the phrase Document Object Model?
html document
Give two examples of document methods that retrieve a single element from the DOM.
querySelector
querySelectorAll
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?
easy to reuse
What console method allows you to inspect the properties of a DOM element object?
console.log
console.dir
Why would a
tag need to be placed at the bottom of the HTML content instead of at the top?
What does document.querySelector() take as its argument and what does it return?
element in dom
What does document.querySelectorAll() take as its argument and what does it return?
all () element in dom
What is the purpose of events and event handling?
for moniter user interaction, when fired, run function
Are all possible parameters required to use a JavaScript method or function?
no
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.
What object is passed into an event listener callback when the event fires?
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
The target event property returns the element that triggered the event. The target property gets the element on which the event originally occurred, opposed to the currentTarget property, which always refers to the element whose event listener triggered the event.
What is the className property of element objects?
The className property of the Element interface gets and sets the value of the class attribute of the specified element.
How do you update the CSS class attribute of an element using JavaScript?
$xxx
$xxx.className = ppp
What is the textContent property of element objects?
The textContent property sets or returns the text content of the specified node, and all its descendants.
How do you update the text within an element using JavaScript?
Use the textContent property to change the text of a div element, e.g. div. textContent = ‘Replacement text’ . The textContent property will set the text of the div to the provided string, replacing any of the existing content.
Is the event parameter of an event listener callback always useful?
Defining the event as a parameter of your handler function is optional but, sometimes (most times), it is useful for the handler function to know about the event that happened.
Does the document.createElement() method insert a new element into the page?
no. it only creat