Answers
I need to select every other div element inside a section element with the id attribute of
"view1".
Which selector do I need? - ✔ document.querySelectorAll('#view1 div:nth-of-type(2n)')
Select ALL of the things found within the Document Object Model (no partial credit): - ✔
nodes
attributes
elements
whitespace
Which method will select only one element from the DOM? - ✔
document.getElementById()
I need to select ALL of the paragraph elements in the DOM. Which method or methods
will let me do this? (Select ALL that apply) - ✔ document.getElementsByTagName('p')
document.querySelectorAll('p')
The HTML Document Object Model is often referred to as
________________________. - ✔ a tree
I have a div with an id attribute of "divOne". It is inside the body element.
I create a new div like this: var newDiv = document.createElement('div');
I want to add my newDiv to the document AFTER divOne. Which line of code achieves
my goal? - ✔ document.body.appendChild(newDiv);
I create a div element on my page. Inside the div element, I create a paragraph
element.
When discussing the relationship of the div element to the paragraph element, the div is
referred to as the _______________ of the paragraph. - ✔ parent
There are 5 paragraphs in the DOM. I need to change the text color of the 2nd
paragraph to white.
Which line of code will achieve my goal? - ✔ document.getElementsByTagName('p')
[1].style.color = 'white';
The textContent property of an HTML element may contain HTML markup. - ✔ False
I have created a paragraph with javascript. I still need to create the text to go in it.
Which method do I use to create the text? - ✔ document.createTextNode()
Look at the following line of code:
, document.elem.addEventListener('click',function(magic){console.log('abracadabra')};
What does "magic" refer to? - ✔ the event object
When an event triggers on the element that creates the event, and then moves outward
to trigger the same event on a container element, it is called event _______________. -
✔ bubbling
Before calling an initApp() function, it is good practice to listen for the
DOMContentLoaded event OR the _____________________ event of the document so
we know the DOM elements we want to select exist. - ✔ readystatechange
I have created a function named doTheStuff. Select the correct and proper line of code
to call doTheStuff with an event listener: - ✔ button.addEventListener("click",
doTheStuff, false);
Which type of storage may still be retrieved after we close our browser and then revisit
the web app at another time? - ✔ localStorage
I am adding a click event listener to a div. The div is a child of the body element.
The body element already has a click event. If I click on the div, the click event of the
body will also occur.
Help me complete this code by filling in the blank (exact match, case-sensitive) to
prevent the click event of the body from firing.
document.myDiv.addEventListener('click', function(e){
e.___________________ ;
console.log('I hope you get it!');
}); - ✔ stopPropagation()
I have an HTML form. I want to apply form validation via JavaScript instead of letting the
form submit right away. To keep this from happening, JavaScript lets me apply
_____________________ to the submit event. - ✔ preventDefault()
Look at the following line of code:
document.element.addEventListener('click',function(event){console.log(event.target)};
We are listening for the click event. When a click occurs, it calls the anonymous
function.
What is the event.target referring to? - ✔ Whichever element initially triggered the click
event.
The addEventListener has 3 parameters: the event to listen for, the function to call, and
optionally, the ________________. - ✔ useCapture
We use event listeners instead of putting JavaScript inline in our HTML elements. This
separation of concerns is a principle of ___________________________. - ✔
Unobtrusive JavaScript