272
Chapter 4.5
Create JS le Add CD to Top 5
Start over
Add CD rankings
function startOver() {
var top5Element = document._____________(“top5”);
var cdsElement = document.getElementById(“______”);
while (_______________.hasChildNodes()) {
var firstChild = top5Element.______________;
if (firstChild._____________.toLowerCase() == “img”) {
____________.appendChild(firstChild);
} else {
top5Element.removeChild(________________);
}
}
____________________;
}
It’s time to exercise your DOM skills one more time. The startOver() function
needs to do several things:
1. Run through each of the children of the “top5” <div>.
2. Any CD cover images need to be added back to the top of the page.
3. And other elements, like <span>s, need to be removed from the page.
See if you can ll in the blanks, and nish off the JavaScript in top5.js.
This one is a little tricky. Remember,
once all the CD covers are back up top,
you should be able to click on them and
have addToTop5() get called. Maybe
there’s a function that does that?
<form><p>
<input type=”button” value=”Start Over” onClick=”startOver();” />
</p></form>
Now you just need to update top5.html, and set
the “Start Over” button to call your completed
startOver() function:
Always remember to connect your
HTML buttons and elements to
your JavaScript code.
start over