Extra Practice
Remember: Learning to program takes practice! It helps to see concepts over and over, and it's always good to try things more than once. We learn much more the second time we do something. Use the exercises and additional self-checks below to practice.
1. Save Buttons
Review the code, then answer the questions below.
let saveButtons = document.querySelectorAll('.save-button');
for (let button of saveButtons){
button.addEventListener('click', function(event){
let contentID = event.target.dataset.id;
console.log(`Saving ${contentID}`);
});
}
What is saveButtons equal-to?
undefinedsaveButtons contains an Array-like collection of DOM elements.Inside the for loop, what name is used to refer to each individual button element?
saveButtons[]buttoneventundefinedfor loop, the button variable refers to each individual button element during each iteration of the loop.What will event.target refer to inside the event listener?
undefinedevent.target property will refer to the button element the user clicked.What event is being listened for?
mouseoverclickloadDOMContentLoadedclick event is being listened for.What attribute on the save button would have contained the contentID?
data-contentIDdata-idcontentIDIDdata-id attribute would be accessible as event.target.dataset.id.Visit Content Online
The content on this page has been removed from your PDF or ebook format. You may view the content by visiting this book online.