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
you’re on your way 4
247
developing dom apps
With the HTML and CSS already written, all that’s left for
you to take care of is the JavaScript. Let’s gure out what
needs to be done, and start writing some code.
What’s the game plan?
Add a ranking number to each CD, so
users can see the order of the Top 5.
Write a function that clears the
user’s choices and starts over.
Write a function that adds a CD to
the Top 5 list when the CD’s cover
is clicked on.
Create a new le to store the page’s
JavaScript code.
This is the easy part... let’s call
the new le top5.js.
The DOM makes tasks like this
pretty easy. We can put this
code in addToTop5(), also.
We’ll have to add an onClick() event
handler to each CD cover image to
handle this. Then we can create a new
function, called addToTop5().
1
2
3
4
Start out by taking care of Step 1. Create a new le and name it top5.js. Go ahead and create a
function called addToTop5() to handle Step 2, and another function named startOver() to
handle Step 4. We’ll write the code for Step 3 as part of the addToTop5() function, so you don’t
need a separate function for that step. You can leave all of these functions blank for now; we’ll ll
each one in as we go through the chapter.
Be sure you’ve made these changes before you turn the page, and then save your new JavaScript le
as top5.js in the top5/ directory, alongside top5.html and top5.css.
An onClick event handler ...
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