Skip to Content
Head Rush Ajax
book

Head Rush Ajax

by Brett McLaughlin
March 2006
Beginner to intermediate
448 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Head Rush Ajax
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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally

Publisher Resources

ISBN: 0596102259Errata PageSupplemental Content