0% found this document useful (0 votes)
10 views

Beginning JavaScript und CSS development with jQuery 1. ed Edition Richard York download

The document provides information about the book 'Beginning JavaScript and CSS Development with jQuery' by Richard York, including its ISBN, publication details, and a brief overview of its content. It covers various aspects of jQuery, including its API, event handling, content manipulation, and AJAX. Additionally, it lists several related ebooks available for download on ebookultra.com.

Uploaded by

tetsanieta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Beginning JavaScript und CSS development with jQuery 1. ed Edition Richard York download

The document provides information about the book 'Beginning JavaScript and CSS Development with jQuery' by Richard York, including its ISBN, publication details, and a brief overview of its content. It covers various aspects of jQuery, including its API, event handling, content manipulation, and AJAX. Additionally, it lists several related ebooks available for download on ebookultra.com.

Uploaded by

tetsanieta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Beginning JavaScript und CSS development with

jQuery 1. ed Edition Richard York download

https://ebookultra.com/download/beginning-javascript-und-css-
development-with-jquery-1-ed-edition-richard-york/

Explore and download more ebooks or textbooks


at ebookultra.com
We have selected some products that you may be interested in
Click the link to download now or visit ebookultra.com
for more options!.

Beginning CSS Cascading Style Sheets for Web Design Wrox


Beginning Guides 2nd Edition Richard York

https://ebookultra.com/download/beginning-css-cascading-style-sheets-
for-web-design-wrox-beginning-guides-2nd-edition-richard-york/

Joomla 1 5 JavaScript jQuery 1st Edition Jose Argudo


Blanco

https://ebookultra.com/download/joomla-1-5-javascript-jquery-1st-
edition-jose-argudo-blanco/

Beginning JavaScript 3rd ed Edition Paul Wilton

https://ebookultra.com/download/beginning-javascript-3rd-ed-edition-
paul-wilton/

Professional XMPP Programming with JavaScript and jQuery


1st Edition Jack Moffitt

https://ebookultra.com/download/professional-xmpp-programming-with-
javascript-and-jquery-1st-edition-jack-moffitt/
Beginning Windows Store Application Development HTML and
JavaScript Edition Scott Isaacs

https://ebookultra.com/download/beginning-windows-store-application-
development-html-and-javascript-edition-scott-isaacs/

Html 5 Black Book Covers Css 3 Javascript Xml Xhtml Ajax


Php And Jquery 2Ed 2nd Edition Dt Editorial Services

https://ebookultra.com/download/html-5-black-book-covers-
css-3-javascript-xml-xhtml-ajax-php-and-jquery-2ed-2nd-edition-dt-
editorial-services/

jQuery and JavaScript Phrasebook 1st Edition Brad Dayley

https://ebookultra.com/download/jquery-and-javascript-phrasebook-1st-
edition-brad-dayley/

Drupal 6 JavaScript and jQuery 1st Edition Matt Butcher

https://ebookultra.com/download/drupal-6-javascript-and-jquery-1st-
edition-matt-butcher/

Beginning JavaScript 5th Edition Jeremy Mcpeak

https://ebookultra.com/download/beginning-javascript-5th-edition-
jeremy-mcpeak/
Beginning JavaScript und CSS development with jQuery
1. ed Edition Richard York Digital Instant Download
Author(s): Richard York
ISBN(s): 9780470227794, 0470227796
Edition: 1. ed
File Details: PDF, 7.18 MB
Year: 2009
Language: english
Beginning
JavaScript®and CSS Development with jQuery
Richard York

27794ffirs.indd 5 3/16/09 3:14:20 PM


Beginning JavaScript® and CSS Development with jQuery
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-0-470-22779-4

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

Library of Congress Cataloging-in-Publication Data

York, Richard.
Beginning JavaScript and CSS development with jQuery / Richard York.
p. cm.
Includes index.
ISBN 978-0-470-22779-4 (paper/website)
1. JavaScript (Computer program language) 2. Web sites--Design. 3. Cascading style sheets. I. Title.
QA76.73.J38Y67 2009
006.7’6--dc22
2009005636

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA
01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions
Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at
http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including
without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or pro-
motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold
with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If
professional assistance is required, the services of a competent professional person should be sought. Neither the publisher
nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this
work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses
the information the organization or Web site may provide or recommendations it may make. Further, readers should be
aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written
and when it is read.

For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trade-
marks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries,
and may not be used without written permission. JavaScript is a registered trademark of Sun Microsystems, Inc. All other
trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor
mentioned in this book.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in
electronic books.

27794ffirs.indd 6 3/16/09 3:14:20 PM


Contents

Introduction xix

Part I: jQuery API 1

Chapter 1: Introduction to jQuery 3


What Does jQuery Do for Me? 4
Who Develops jQuery? 5
Obtaining jQuery 5
Installing jQuery 5
Programming Conventions 8
XHTML and CSS Conventions 9
JavaScript Conventions 16
Summary 25

Chapter 2: Selecting and Filtering 27


The Origin of the Selectors API 28
Using the Selectors API 29
Filtering a Selection 37
Searching within a Selection with find() 38
Finding an Element’s Siblings with siblings() 39
Selecting Specific Siblings 42
Searching Ancestors Using the parents() and parent() Methods 46
Selecting Children Elements 48
Selecting Elements via What You Don’t Want 50
Selecting a Snippet of the Results 51
Adding More Elements to a Selection 53
Selecting One Specific Element from a Result Set 55
Summary 66
Exercises 66

Chapter 3: Events 69
Assigning an Event with the Traditional Event Model 69
Assigning Events with the W3C Event Model 72
The this Object 73
The event Object 75
Contents
The Microsoft JScript Event Model 77
Creating a Universal Event API 78
Binding Events with jQuery’s bind() Method 80
Binding Events with jQuery’s Event Methods 82
Triggering Events 83
Summary 93
Exercises 93

Chapter 4: Manipulating Content and Attributes 95


Setting and Accessing Attributes 95
Manipulating Class Names 105
Manipulating HTML and Text Content 109
Getting, Setting, and Removing Content 110
Appending and Prepending Content 115
Inserting Beside Content 123
Inserting Beside Content via a Selection 125
Wrapping Content 129
Replacing Elements 146
Removing Content 150
Cloning Content 154
Summary 162
Exercises 163

Chapter 5: Arrays and Iteration 165


Basic Iteration 165
Calling each() Directly 167
Variable Scope 168
Emulating break and continue 170
Iterating a Selection 172
Filtering Selections and Arrays 173
Filtering a Selection 174
Filtering a Selection with a Callback Function 175
Filtering an Array 177
Mapping a Selection or an Array 180
Mapping a Selection 180
Mapping an Array 183
Array Utility Methods 196
Making an Array 197
Finding a Value within an Array 197

xii
Contents
Merging Two Arrays 198
Removing Duplicate Items 199
Summary 204
Exercises 205

Chapter 6: CSS 207


The css() Method 207
The outerWidth() and outerHeight() Methods 208
Summary 217
Exercises 217

Chapter 7: AJAX 219


Making a Server Request 220
What’s the Difference between GET and POST? 220
Formats Used to Transport Data with an AJAX Request 221
Making a GET Request with jQuery 222
Loading HTML Snippets from the Server 240
Dynamically Loading JavaScript 265
AJAX Events 267
Making an AJAX-Style File Upload 272
Summary 275
Exercises 276

Chapter 8: Effects 277


Showing and Hiding Elements 277
Sliding Elements 279
Fading Elements 280
Custom Animation 281
Summary 283
Exercises 284

Chapter 9: Plugins 285


Writing a Plugin 285
Good Practice for jQuery Plugin Development 295
Summary 296
Exercises 296

xiii
Contents

Part II: jQuery UI 297

Chapter 10: Implementing Drag-and-Drop 299


Making Elements Draggable 300
Making Elements Draggable with Ghosting 308
Dragging between Windows in Safari 311
Delegating Drop Zones for Dragged Elements 314
Summary 326
Exercises 326

Chapter 11: Drag-and-Drop Sorting 327


Making a List Sortable 327
Customizing Sortables 338
Saving the State of Sorted Lists 347
Summary 353
Exercises 354

Chapter 12: Selection by Drawing a Box 355


Introducing the Selectables Plugin 355
Summary 372
Exercises 372

Chapter 13: Accordion UI 373


Building an Accordion UI 373
Setting Auto-Height 376
Changing the Default Pane 377
Toggling the alwaysOpen Option 380
Changing the Accordion Event 380
Filling the Height of the Parent Element 381
Setting the Header Elements 381
Styling Selected Panes 384
Selecting a Content Pane by Location 387
Summary 390
Exercises 391

xiv
Contents
Chapter 14: Datepicker 393
Implementing a Datepicker 393
Styling the Datepicker 395
Setting the Range of Allowed Dates 403
Allowing a Date Range to Be Selected 404
Localizing the Datepicker 405
Setting the Date Format 405
Localizing Datepicker Text 406
Changing the Starting Weekday 407
Summary 408
Exercises 408

Chapter 15: Dialogs 409


Implementing a Dialog 409
Examining a Dialog’s Markup 411
Making a Modal Dialog 417
Auto-Opening the Dialog 419
Controlling Dynamic Interaction 420
Animating the Dialog 421
Working with Dialog Events 422
Summary 423
Exercises 424

Chapter 16: Tabs 425


Implementing Tabs 425
Loading Remote Content via AJAX 432
Animating Tab Transitions 436
Summary 437
What Next? 437
Exercises 438

Appendix A: Answers to Exercises 439


Chapter 2 439
Chapter 3 439
Chapter 4 440
Chapter 5 441

xv
Contents
Chapter 6 441
Chapter 7 442
Chapter 8 442
Chapter 9 443
Chapter 10 443
Chapter 11 444
Chapter 12 444
Chapter 13 444
Chapter 14 445
Chapter 15 445
Chapter 16 445

Appendix B: Selectors Supported by jQuery 447

Appendix C: Selecting and Filtering 451

Appendix D: Events 453


Event Object Normalization 455

Appendix E: Manipulating Attributes and Data Caching 457

Appendix F: Manipulating Content 459

Appendix G: AJAX Methods 461

Appendix H: CSS 465

Appendix I: Utilities 467

Appendix J: Draggables and Droppables 469

Appendix K: Sortables 475

Appendix L: Selectables 479


Notes 480

Appendix M: Effects 481


Speed 481
Callback Function 481

xvi
Contents
Appendix N: Accordion 485

Appendix O: Datepicker 487

Appendix P: Dialog 497

Appendix Q: Tabs 501

Appendix R: Re-Sizables 505

Appendix S: Sliders 509


Index 511

xvii
Introduction

The jQuery JavaScript framework is a rising star in the world of web development. JavaScript frame-
works in general have grown to become immensely popular in the past few years in parallel with the
ever-increasing presence of JavaScript-driven, so-called Web 2.0 websites that make heavy use of tech-
nologies like AJAX and JavaScript in general for slick graphical enhancements that would be impossible
or much more cumbersome to incorporate without JavaScript.

jQuery’s mission as a JavaScript library is simple — it strives to make the lives of web developers eas-
ier by patching over certain portions of cross-browser development and by making other tasks com-
monly needed by developers much easier. jQuery has the real, proven ability to reduce many lines of
plain-vanilla JavaScript to just a few lines, and, in many cases, just a single line. jQuery strives to
remove barriers to JavaScript development by removing redundancy wherever possible and normal-
izing cross-browser JavaScript development in key areas where browsers would otherwise differ,
such as Microsoft’s Event API and the W3C Event API, and other, more remedial tasks like getting the
mouse cursor’s position when an event has taken place.

jQuery is a compact, lightweight library that currently works in Microsoft’s Internet Explorer browser
from version 6 on, Firefox from version 1.5 on, Safari from version 2.0.2 on, Opera from version 9 on,
and Google’s new Chrome browser from version 0.2 on. Getting started with jQuery is very easy — all
you have to do is include a single link of markup in your HTML or XHTML documents that includes
the library. Throughout this book, I demonstrate jQuery’s API (Application Programming Interface)
components in detail and show you how all the nuts and bolts of this framework come together to
enable you to rapidly develop client-side applications.

I also cover the jQuery UI library, which makes redundant user-interface (UI) tasks on the client side
ridiculously easy and accessible to everyday web developers who might not have much JavaScript pro-
gramming expertise. Have you ever wanted to create an animated accordion effect like the one found
on Apple’s Mac home page at www.apple.com/mac? With jQuery, not only can you create this effect with
your own look and feel, but also it’s dead simple to boot.

Have you ever wondered how websites make virtual pop-up windows using JavaScript, HTML, and CSS?
The jQuery UI library provides the ability to create these pop-up windows and includes the ability to
animate transitions like fading the window on and off, or having it re-size from very small to full sized.
The jQuery UI library gives you the ability to use animations and transitions using JavaScript, markup,
and CSS that you may have thought previously could only have been done with Adobe’s Flash player.

The jQuery framework itself has enjoyed a great deal of mainstream exposure. It has been used by
Google, Dell, Digg, NBC, CBS, Netflix, The Mozilla Foundation, and the popular WordPress and Drupal
PHP frameworks.

jQuery is fast — superfast — and it has a small footprint. It’s only 15 KB, using the compressed and
gzipped version.

27794flast.indd 19 3/16/09 11:33:36 AM


Introduction
jQuery gives you the ability to provide complex, professional, visually driven user interfaces and effects
with very few lines of code. What may have taken other developers days or even weeks to accomplish
can be done with jQuery in just a few hours.

Who This Book Is For


This book is for anyone interested in doing more with less code! You should have a basic understanding
of JavaScript. I review some basic JavaScript programming concepts, such as the Event API, but I do not
go into great detail about the JavaScript language itself. You’ll want to have at least a basic grasp of the
Document Object Model, or DOM, and basic JavaScript programming syntax. Additionally, you’ll need
to know your way around CSS and HTML, since knowledge of those technologies is also assumed. A
complete beginner might be able to grasp what is taking place in the examples in this book but might
not understand certain terminology and programming concepts that would be presented in a beginner’s
JavaScript guide, so if you are a beginner and insist with pressing forward, I recommend doing so with a
beginning JavaScript book on hand as well. Specifically, I recommend the following Wrox books for
more help with the basics:

❑❑ Beginning Web Programming with HTML, XHTML, and CSS, 2nd ed. (2008), by Jon Duckett
❑❑ Beginning CSS: Cascading Style Sheets for Web Design, 2nd ed. (2007), also written by yours truly.
❑❑ Beginning JavaScript, 3rd ed. (2007), by Paul Wilton and Jeremy McPeak

For further knowledge of JavaScript above and beyond what is covered in this book, I recommend
Professional JavaScript for Web Developers, 2nd ed. (2009), by Nicholas C. Zakas.

What This Book Covers


This book covers the jQuery JavaScript framework and the jQuery UI JavaScript framework and demon-
strates in great detail how to use the jQuery framework to get more results more quickly out of JavaScript
programming. I cover each method exposed by jQuery’s API, which contains methods to make common,
redundant tasks go much more quickly in less code. Some examples are methods that help you to select
elements from a markup document through the DOM and methods that help you to traverse through
those selections and filter them using jQuery’s fine-grained controls. This makes working with the DOM
easier and more effortless. I also cover how jQuery eliminates certain cross-browser, cross-platform devel-
opment headaches like the event model; not only does it eliminate these headaches, but it also makes it
easier to work with events by reducing the amount of code that you need to write to attach events. It even
gives you the ability to simulate events.

Later in the book, I cover how you can leverage the jQuery UI library to make graphically driven UI
widgets. jQuery gives you the ability to break content up among multiple tabs in the same page. You
have the ability to customize the look and feel of the tabs, and even to create a polished look and feel by
providing different effects that come in when you mouse over tabs and click on them. The jQuery UI
library also makes it easy to create accordion sidebars, like the one on Apple’s Mac website. These side-
bars have two or more panels, and when you mouse over an item, one pane transitions to another via a
smooth, seamless animation wherein the preceding pane collapses and the proceeding pane expands.

xx

27794flast.indd 20 3/16/09 11:33:36 AM


Introduction
The jQuery UI library also gives you the ability to make any element draggable with the mouse; by click-
ing and holding and moving the mouse, you can move elements around on a page. It also makes it really
easy to create drag-and-drop user interfaces. This can be used to make a dropping zone where you take
elements from other parts of the page and drop them in another, as you would in your operating sys-
tem’s file manager when you want to move a folder from one place to another. You can also make lists
that are sortable via drag-and-drop, rearranging elements based on where you drop them. You can also
have a user interface where you drag the mouse cursor to make a selection, as you would in your oper-
ating system’s file manager when you want to select more than one file. Then jQuery UI also exposes the
ability to re-size elements on a page using the mouse. All of those neat things that you can do on your
computer’s desktop, you can also do in a web browser with jQuery UI.

jQuery UI also provides a widget for entering a date into a field using a nice, accessible JavaScript-
driven calendar that pops up when you click on an input field.

You can also make custom pop-up dialogues that are like virtual pop-up windows, except they don’t
open a separate browser window — they come up using markup, CSS, and JavaScript.

Another widget that jQuery UI provides is a graphical slider bar, similar to your media player’s volume
control.

As jQuery has done for JavaScript programming in general, jQuery UI strives to do for redundant
graphical user interface (GUI) tasks. jQuery UI gives you the ability to make professional user-interface
widgets with much less development effort.

If you’re interested in reading news about jQuery, how it’s evolving, and topics related to web develop-
ment, you may be interested in reading the official jQuery blog at blog.jquery.com, or jQuery’s creator,
John Resig’s blog, at www.ejohn.org.

If you are in need of help, you can participate in programming discussion at p2p.wrox.com, which
you can join for free to ask programming questions in moderated forums. There are also program-
ming forums provided by the jQuery community, which you can learn more about at
http://docs.jquery.com/Discussion.

Finally, I maintain a blog and website at www.deadmarshes.com, where you can contact me directly with
your thoughts about the book or read about the web development projects I’m working on.

How This Book Is Structured


This book is divided into two parts: The first half of the book covers the basic API exposed by the jQuery
library, and the second half covers the jQuery UI library.

Part 1: jQuery API


❑❑ Chapter 1: Introduction to jQuery — In this first chapter, I discuss a little of where jQuery came
from and why it was needed. Then I walk you through downloading and creating your first
jQuery-enabled JavaScript.

xxi

27794flast.indd 21 3/16/09 11:33:36 AM


Introduction
❑❑ Chapter 2: Selecting and Filtering — This chapter introduces jQuery’s selector engine, which
uses selectors like you will have used with CSS to make selections from the DOM. Then I talk
about the various methods that jQuery exposes for working with a selection, to give you fine-
grained control over what elements you’re working with from the DOM. I talk about methods
that let you select, ancestor elements, parent elements, sibling elements, descendent elements,
how to remove elements from a selection, how to add elements to a selection, and how to
reduce a selection to a specific subset of elements.
❑❑ Chapter 3: Events — In this chapter, I begin by reviewing the event model as you find it in plain-
vanilla JavaScript. You have the traditional event model, the W3C’s event model, and Microsoft’s
event model. I discuss the differences between these and why jQuery needed an entirely new
Event API to make the situation easier for web developers. Then I present jQuery’s Event API
and how you use it.
❑❑ Chapter 4: Manipulating Content and Attributes — In Chapter 4, you learn how to use the
methods that jQuery exposes for working with content, text and HTML, and element attributes.
jQuery provides methods for doing just about everything you’d want to do to an element.
❑❑ Chapter 5: Arrays and Iteration — In Chapter 5, I talk about how you can enumerate over a
selection of elements or an array using jQuery. As with everything else, jQuery provides an eas-
ier way that requires fewer lines of code to loop over the contents of an array or a selection of
elements from the DOM.
❑❑ Chapter 6: CSS — In this chapter, you learn about the methods that jQuery exposes for working
with CSS properties and declarations. jQuery provides intuitive and versatile methods that let
you manipulate CSS in a variety of ways.
❑❑ Chapter 7: AJAX — Chapter 7 elaborates on the methods that jQuery exposes for making AJAX
requests from a server, which allows you to request server content without working directly
with the XMLHttpRequest object and supports handling server responses in a variety of formats.
❑❑ Chapter 8: Effects — In Chapter 8, I discuss some helper methods that jQuery exposes for dis-
covering what browser and browser version you’re working with, whether you’re working with
a browser that supports the standard W3C box model for CSS, and a variety of odds and ends
methods for working with objects, arrays, functions, and strings.
❑❑ Chapter 9: Plugins — In this chapter, I describe how you can make your own plugins for jQuery.

Part II: jQuery UI


❑❑ Chapter 10: Implementing Drag-and-Drop — In Chapter 10, I begin my coverage of the jQuery
UI library by discussing how you make individual elements draggable and how you make a
drag-and-drop interface where you take one element and place it on top of another to create a
complete drag-and-drop sequence.
❑❑ Chapter 11: Drag-and-Drop Sorting — In Chapter 11, I discuss how you make lists sortable
using drag-and-drop.
❑❑ Chapter 12: Selection by Drawing a Box — In Chapter 12, I cover the portion of the jQuery UI
library that lets you make a selection by drawing a box with your mouse, just like you would do
in your OS’s file management application.
❑❑ Chapter 13: Accordion UI — In this chapter, I discuss how to make a really neat, polished-looking
sidebar that has panes that transition like an accordion. When you mouse over an element, one
pane collapses via a slick animation, and another one expands, also via an animation.

xxii

27794flast.indd 22 3/16/09 11:33:36 AM


Introduction
❑❑ Chapter 14: Datepicker — In Chapter 14, I cover how you make a standard form input field
into a Datepicker, using jQuery’s Datepicker widget.
❑❑ Chapter 15: Dialogs — In Chapter 15, I talk about how you create virtual pop-up windows,
using the jQuery UI library, that look and act like real pop-up windows but are entirely con-
tained in the same web page that launches them and are built using pure markup, CSS, and
JavaScript.
❑❑ Chapter 16: Tabs — In Chapter 16, I discuss the jQuery UI tab component, which allows you to
take a document and split it into several tabs and navigate between those tabs without needing
to load another page.
❑❑ Appendixes — Appendix A contains the answers to chapter exercises. Appendix B through
Appendix S contain reference materials for jQuery and jQuery UI.

What You Need to Use This Book


To make use of the examples in this book, you need the following:

❑❑ Several Internet browsers to test your web pages


❑❑ Text-editing software or your favorite IDE

Designing content for websites requires being able to reach more than one type of audience. Some of
your audience may be using different operating systems or different browsers other than those you have
installed on your computer. This book focuses on the most popular browsers available at the time of this
writing as supported:

❑❑ Microsoft Internet Explorer 6 or newer for Windows


❑❑ Safari for Mac OS X, version 2 or newer
❑❑ Mozilla Firefox for Mac OS X, Windows, or Linux
❑❑ Opera for Mac OS X, Windows and Linux, version 9 or newer

Conventions
To help you get the most from the text and keep track of what’s happening, I’ve used a number of con-
ventions throughout the book.

First, be aware that not all the figures referenced in the text actually appear in print. This means, for
example, that the screenshots that actually do appear in a chapter might not be numbered in strict
sequence. For example, if you look only at the screenshots in Chapter 3, the first is Figure 3-1, and the
second is Figure 3-3. There is a reference to Figure 3-2 in the text, but the actual screenshot is not printed.
These “missing” screenshots aren’t really missing, though — they are generated by the code download.
It’s just that for all intents and purposes, they are identical to the screenshots that are printed before or
after them and are therefore not needed in the text.

xxiii

27794flast.indd 23 3/16/09 11:33:36 AM


Introduction

Try It Out
The Try It Out is an exercise you should work through, following the text in the book.
1. It usually consists of a set of steps.
2. Each step has a number.
3. Follow the steps through with your copy of the database.

Boxes like this one hold important, not-to-be forgotten information that is directly
relevant to the surrounding text.

Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:

❑❑ We highlight with italics new terms and important words when we introduce them.
❑❑ We show keyboard strokes like this: Ctrl+A.
❑❑ We show URLs and code within the text like so: persistence.properties.
❑❑ We present code in the following way:
We use a monofont type with no highlighting for most code examples.

Also, Visual Studio’s code editor provides a rich color scheme to indicate various parts of code syntax.
That’s a great tool to help you learn language features in the editor and to help prevent mistakes as you
code. To reinforce Visual Studio’s colors, the code listings in this book are colorized using colors similar
to what you would see on screen in Visual Studio working with the book’s code. In order to optimize
print clarity, some colors have a slightly different hue in print from what you see on screen. But all of
the colors for the code in this book should be close enough to the default Visual Studio colors to give
you an accurate representation of the colors.

Source Code
As you work through the examples in this book, you may choose either to type in all the code manually
or to use the source code files that accompany the book. All of the source code used in this book is avail-
able for download at www.wrox.com. Once at the site, simply locate the book’s title (either by using the
Search box or by using one of the title lists) and click on the Download Code link on the book’s detail
page to obtain all the source code for the book.

Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is
978-0-470-22779-4.

Once you download the code, just decompress it with your favorite compression tool. Alternatively, you
can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see
the code available for this book and all other Wrox books.

xxiv

27794flast.indd 24 3/16/09 11:33:36 AM


Random documents with unrelated
content Scribd suggests to you:
THE TWELVE LABORS OF HERCULES
By Thomas Bulfinch

H
ercules was the son of Jupiter and Alcmena. As Juno was always
hostile to the offspring of her husband by mortal mothers, she
declared war against Hercules from his birth. She sent two serpents
to destroy him as he lay in his cradle, but the brave infant strangled
them with his own hands.
He was, however, by the arts of Juno rendered subject to
Eurystheus and compelled to perform all his commands. Eurystheus
gave him a succession of desperate tasks, which are called the
“Twelve Labors of Hercules,” The first was the fight with the Nemean
lion.
The valley of Nemea was infested by a terrible lion. Eurystheus
ordered Hercules to bring him the skin of this monster. After using in
vain his club and arrows against the lion, Hercules strangled the
animal with his hands. He returned carrying the dead lion on his
shoulders; but Eurystheus was so frightened at the sight of it and at
this proof of the prodigious strength of the hero, that he ordered
him to deliver the account of his exploits in future outside the town.
His next labor was the slaughter of the Hydra. This monster
ravaged the country of Argos, and dwelt in a swamp near the well of
Amymone. This well had been discovered by Amymone when the
country was suffering from drought, and the story was that Neptune,
who loved her, had permitted her to touch the rock with his trident,
and a spring of three outlets burst forth. Here the Hydra took up his
position, and Hercules was sent to destroy him. The Hydra had nine
heads, of which the middle one was immortal.
Hercules struck off its heads with his club, but in the place of the
head knocked off, two new ones grew forth each time. At length
with the assistance of his faithful servant Iolaus, he burned away the
heads of the Hydra, and buried the ninth or immortal one under a
huge rock.
Another labor was the cleaning of the Augean stables. Augeas,
King of Elis, had a herd of three thousand oxen, whose stalls had not
been cleansed for thirty years. Hercules brought the rivers Alpheus
and Peneus through them, and cleansed them thoroughly in one
day.
His next labor was of a more delicate kind. Admeta, the daughter
of Eurystheus, longed to obtain the girdle of the Queen of the
Amazons, and Eurystheus ordered Hercules to go and get it. The
Amazons were a nation of women. They were very warlike and held
several flourishing cities. It was their custom to bring up only the
female children; the boys were either sent away to the neighboring
nations or put to death. Hercules was accompanied by a number of
volunteers, and after various adventures at last reached the country
of the Amazons. Hippolyta, the queen, received him kindly, and
consented to yield him her girdle, but Juno, taking the form of an
Amazon, went and persuaded the rest that the strangers were
carrying off their queen. They instantly armed and came in great
numbers down to the ship. Hercules, thinking that Hippolyta had
acted treacherously, slew her, and taking her girdle made sail
homeward.
Another task enjoined him was to bring to Eurystheus the oxen of
Geryon, a monster with three bodies, who dwelt in the island
Erytheia (the red), so called because it lay at the west, under the
rays of the setting sun. This description is thought to apply to Spain,
of which Geryon was king. After traversing various countries,
Hercules reached at length the frontiers of Libya and Europe, where
he raised the two mountains of Calpe and Abyla, as monuments of
his progress, or, according to another account, rent one mountain
into two and left half on each side, forming the straits of Gibraltar,
the two mountains being called the Pillars of Hercules. The oxen
were guarded by the giant Eurytion and his two-headed dog, but
Hercules killed the giant and his dog and brought away the oxen in
safety to Eurystheus.
The most difficult labor of all was getting the golden apples of the
Hesperides, for Hercules did not know where to find them. These
were the apples which Juno had received at her wedding from the
goddess of the Earth, and which she had intrusted to the keeping of
the daughters of Hesperus, assisted by a watchful dragon.
A celebrated exploit of Hercules was his victory over Antæus.
Antæus, the son of Terra, the Earth, was a mighty giant and
wrestler, whose strength was invincible so long as he remained in
contact with his mother Earth. He compelled all strangers who came
to his country to wrestle with him, on condition that if conquered (as
they all were) they should be put to death. Hercules encountered
him, and finding that it was of no avail to throw him, for he always
rose with renewed strength from every fall, he lifted him up from the
earth and strangled him in the air.
Cacus was a huge giant, who inhabited a cave on Mount Aventine,
and plundered the surrounding country. When Hercules was driving
home the oxen of Geryon, Cacus stole part of the cattle, while the
hero slept. That their footprints might not serve to show where they
had been driven, he dragged them backward by their tails to his
cave; so their tracks all seemed to show that they had gone in the
opposite direction. Hercules was deceived by this stratagem, and
would have failed to find his oxen, if it had not happened that in
driving the remainder of the herd past the cave where the stolen
ones were concealed, those within began to low, and were thus
discovered. Cacus was slain by Hercules.
The last exploit we shall record was bringing Cerberus from the
lower world. Cerberus was the three-headed dog that guarded the
entrance to Hades. Hercules descended into Hades, accompanied by
Mercury and Minerva. He obtained permission from Pluto to carry
Cerberus to the upper air, provided he could do it without the use of
weapons; and in spite of the monster’s struggling, he seized him,
held him fast, and carried him to Eurystheus, and afterward brought
him back again. When he was in Hades he obtained the liberty of
Theseus, his admirer and imitator, who had been detained a prisoner
there for an unsuccessful attempt to carry off Proserpine.
Hercules in a fit of madness killed his friend Iphitus, and was
condemned for this offence to become the slave of Queen Omphale
for three years. While in this service the hero’s nature seemed
changed. He lived effeminately, wearing at times the dress of a
woman, spinning wool with the handmaidens of Omphale, while the
queen wore his lion’s skin. When this service was ended he married
Dejanira and lived in peace with her three years. On one occasion as
he was travelling with his wife, they came to a river, across which
the Centaur Nessus carried travellers for a stated fee. Hercules
himself forded the river, but gave Dejanira to Nessus to be carried
across. Nessus attempted to run away with her, but Hercules heard
her cries and shot an arrow into the heart of Nessus. The dying
Centaur told Dejanira to take a portion of his blood and keep it, as it
might be used as a charm to preserve the love of her husband.
Dejanira did so and before long fancied she had occasion to use it.
Hercules in one of his conquests had taken prisoner a fair maiden,
named Iole, of whom he seemed more fond than Dejanira approved.
When Hercules was about to offer sacrifices to the gods in honor of
his victory, he sent to his wife for a white robe to use on the
occasion. Dejanira, thinking it a good opportunity to try her love-
spell, steeped the garment in the blood of Nessus. As soon as the
garment became warm on the body of Hercules the poison
penetrated into all his limbs and caused him the most intense agony.
In his frenzy he seized Lichas, who had brought him the fatal robe,
and hurled him into the sea. He wrenched off the garment, but it
stuck to his flesh, and with it he tore away whole pieces of his body.
In this state he embarked on board a ship and was conveyed home.
Dejanira, on seeing what she had unwittingly done, hung herself.
Hercules, prepared to die, ascended Mount Œta, where he built a
funeral pile of trees, gave his bow and arrows to Philoctetes, and
laid himself down on the pile, his head resting on his club, and his
lion’s skin spread over him. With a countenance as serene as if he
were taking his place at a festal board he commanded Philoctetes to
apply the torch. The flames spread apace and soon invested the
whole mass.
The gods themselves felt troubled at seeing the champion of the
earth so brought to his end. But Jupiter with cheerful countenance
thus addressed them: “Fear not. He who conquered all else is not to
be conquered by those flames which you see blazing on Mount Œta.
Only his mother’s share in him can perish; what he derived from me
is immortal. I shall take him, dead to earth, to the heavenly shores,
and I require of you all to receive him kindly.” Jupiter enveloped him
in a cloud, and took him up in a four-horse chariot to dwell among
the stars.
HERCULES’S SEARCH FOR THE
APPLES OF HESPERIDES
By Nathaniel Hawthorne

D
id you ever hear of the golden apples that grew in the garden of
the Hesperides? Ah, those were such apples as would bring a
great price, by the bushel, if any of them could be found growing in
the orchards of nowadays! But there is not, I suppose, a graft of
that wonderful fruit on a single tree in the wide world. Not so much
as a seed of those apples exists any longer.
And, even in the old, old half-forgotten times, before the garden
of the Hesperides was overrun with weeds, a great many people
doubted whether they could be real trees that bore apples of solid
gold upon their branches. All had heard of them, but nobody
remembered to have seen any. Children, nevertheless, used to
listen, open-mouthed, to stories of the golden apple-tree, and
resolved to discover it, when they should be big enough.
Adventurous young men, who desired to do a braver thing than any
of their fellows, set out in quest of this fruit. Many of them returned
no more; none of them brought back the apples. No wonder that
they found it impossible to gather them! It is said that there was a
dragon beneath the tree, with a hundred terrible heads, fifty of
which were always on the watch, while the other fifty slept.
In my opinion it was hardly worth running so much risk for the
sake of a solid golden apple. Had the apples been sweet, mellow,
and juicy, indeed that would be another matter. There might then
have been some sense in trying to get at them, in spite of the
hundred-headed dragon.
But, as I have already told you, it was quite a common thing with
young persons, when tired of too much peace and rest, to go in
search of the garden of the Hesperides. And once the adventure was
undertaken by a hero who had enjoyed very little peace or rest since
he came into the world. At the time of which I am going to speak,
he was wandering through the pleasant land of Italy, with a mighty
club in his hand, and a bow and quiver slung across his shoulders.
He was wrapt in the skin of the biggest and fiercest lion that ever
had been seen, and which he himself had killed; and though, on the
whole, he was kind, and generous, and noble, there was a good deal
of the lion’s fierceness in his heart. As he went on his way, he
continually inquired whether that were the right road to the famous
garden. But none of the country people knew anything about the
matter, and many looked as if they would have laughed at the
question, if the stranger had not carried so very big a club.
So he journeyed on and on, still making the same inquiry, until, at
last, he came to the brink of a river where some beautiful young
women sat twining wreaths of flowers.
“Can you tell me, pretty maidens,” asked the stranger, “whether
this is the right way to the garden of the Hesperides?”
The young women had been having a fine time together, weaving
the flowers into wreaths, and crowning one another’s heads. And
there seemed to be a kind of magic in the touch of their fingers, that
made the flowers more fresh and dewy, and of brighter hues, and
sweeter fragrance, while they played with them, than even when
they had been growing on their native stems. But, on hearing the
stranger’s question, they dropped all their flowers on the grass, and
gazed at him with astonishment.
“The garden of the Hesperides!” cried one. “We thought mortals
had been weary of seeking it, after so many disappointments. And
pray, adventurous traveller, what do you want there?”
“A certain king, who is my cousin,” replied he, “has ordered me to
get him three of the golden apples.”
“Most of the young men who go in quest of these apples,”
observed another of the damsels, “desire to obtain them for
themselves, or to present them to some fair maiden whom they
love. Do you, then, love this king, your cousin, so very much?”
“Perhaps not,” replied the stranger, sighing. “He has often been
severe and cruel to me. But it is my destiny to obey him.”
“And do you know,” asked the damsel who had first spoken, “that
a terrible dragon, with a hundred heads, keeps watch under the
golden apple-tree?”
“I know it well,” answered the stranger, calmly. “But from my
cradle upwards, it has been my business, and almost my pastime, to
deal with serpents and dragons.”
The young women looked at his massive club, and at the shaggy
lion’s skin which he wore, and likewise at his heroic limbs and figure;
and they whispered to each other that the stranger appeared to be
one who might reasonably expect to perform deeds far beyond the
might of other men. But, then, the dragon with a hundred heads!
What mortal, even if he possessed a hundred lives, could hope to
escape the fangs of such a monster? So kind-hearted were the
maidens, that they could not bear to see this brave and handsome
traveller attempt what was so very dangerous, and devote himself,
most probably, to become a meal for the dragon’s hundred ravenous
mouths.
“Go back,” cried they all—“go back to your own home! Your
mother, beholding you safe and sound, will shed tears of joy; and
what can she do more, should you win ever so great a victory? No
matter for the golden apples! No matter for the king, your cruel
cousin! We do not wish the dragon with the hundred heads to eat
you up!”
The stranger seemed to grow impatient at these remonstrances.
He carelessly lifted his mighty club, and let it fall upon a rock that lay
half buried in the earth, near by. With the force of that idle blow, the
great rock was shattered all to pieces. It cost the stranger no more
effort to achieve this feat of a giant’s strength than for one of the
young maidens to touch her sister’s rosy cheek with a flower.
“Do you not believe,” said he, looking at the damsels with a smile,
“that such a blow would have crushed one of the dragon’s hundred
heads?”
Then he sat down on the grass, and told them the story of his life,
or as much of it as he could remember, from the day when he was
first cradled in a warrior’s brazen shield. While he lay there, two
immense serpents came gliding over the floor, and opened their
hideous jaws to devour him; and he, a baby of a few months old,
had gripped one of the fierce snakes in each of his little fists, and
strangled them to death. When he was but a stripling, he had killed
a huge lion, almost as big as the one whose vast and shaggy hide he
now wore upon his shoulders. The next thing that he had done was
to fight a battle with an ugly sort of monster, called a hydra, which
had no less than nine heads, and exceedingly sharp teeth in every
one.
“But the dragon of the Hesperides, you know,” observed one of
the damsels, “has a hundred heads!”
“Nevertheless,” replied the stranger, “I would rather fight two such
dragons than a single hydra. For, as fast as I cut off a head, two
others grew in its place; and, besides, there was one of the heads
that could not possibly be killed, but kept biting as fiercely as ever,
long after it was cut off. So I was forced to bury it under a stone,
where it is doubtless alive to this very day. But the hydra’s body, and
its eight other heads, will never do any further mischief.”
The damsels, judging that the story was likely to last a good
while, had been preparing a repast of bread and grapes, that the
stranger might refresh himself in the intervals of his talk. They took
pleasure in helping him to this simple food; and, now and then, one
of them would put a sweet grape between her rosy lips, lest it
should make him bashful to eat alone.
The traveller proceeded to tell how he had chased a very swift
stag, for a twelvemonth together, without ever stopping to take
breath, and had at last caught it by the antlers, and carried it home
alive. And he had fought with a very odd race of people, half horses
and half men, and had put them all to death, from a sense of duty in
order that their ugly figures might never be seen any more. Besides
all this, he took to himself great credit for having cleaned out a
stable.
“Do you call that a wonderful exploit?” asked one of the young
maidens, with a smile. “Any clown in the country has done as much!”
“Had it been an ordinary stable,” replied the stranger, “I should
not have mentioned it. But this was so gigantic a task that it would
have taken me all my life to perform it, if I had not luckily thought of
turning the channel of a river through the stable-door. That did the
business in a very short time!”
Seeing how earnestly his fair auditors listened, he next told them
how he had shot some monstrous birds, and had caught a wild bull
alive and let him go again, and had tamed a number of very wild
horses, and had conquered Hippolyta, the warlike Queen of the
Amazons. He mentioned, likewise, that he had taken off Hippolyta’s
enchanted girdle, and had given it to the daughter of his cousin, the
king.
“Was it the girdle of Venus,” inquired the prettiest of the damsels,
“which makes women beautiful?”
“No,” answered the stranger. “It had formerly been the sword-belt
of Mars; and it can only make the wearer valiant and courageous.”
“An old sword-belt!” cried the damsel, tossing her head. “Then I
should not care about having it!”
“You are right,” said the stranger.
Going on with his wonderful narrative, he informed the maidens
that as strange an adventure as ever happened was when he fought
with Geryon, the six-legged man. This was a very odd and frightful
sort of figure, as you may well believe. Any person, looking at his
tracks in the sand or snow, would suppose that three sociable
companions had been walking along together. On hearing his
footsteps at a little distance, it was no more than reasonable to
judge that several people must be coming. But it was only the
strange man Geryon clattering onward, with his six legs!
Six legs, and one gigantic body! Certainly, he must have been a
very queer monster to look at; and, my stars, what a waste of shoe
leather!
When the stranger had finished the story of his adventures, he
looked around at the attentive faces of the maidens.
“Perhaps you may have heard of me before,” said he, modestly.
“My name is Hercules!”
“We had already guessed it,” replied the maidens; “for your
wonderful deeds are known all over the world. We do not think it
strange, any longer, that you should set out in quest of the golden
apples of the Hesperides. Come, sisters, let us crown the hero with
flowers!”
Then they flung beautiful wreaths over his stately head and
mighty shoulders, so that the lion’s skin was almost entirely covered
with roses. They took possession of his ponderous club, and so
entwined it about with the brightest, softest, and most fragrant
blossoms, that not a finger’s breadth of its oaken substance could be
seen. It looked all like a huge bunch of flowers. Lastly, they joined
hands, and danced around him, chanting words which became
poetry of their own accord, and grew into a choral song, in honor of
the illustrious Hercules.
And Hercules was rejoiced, as any other hero would have been, to
know that these fair young girls had heard of the valiant deeds
which it had cost him so much toil and danger to achieve. But, still,
he was not satisfied. He could not think that what he had already
done was worthy of so much honor, while there remained any bold
or difficult adventure to be undertaken.
“Dear maidens,” said he, when they paused to take breath, “now
that you know my name, will you not tell me how I am to reach the
garden of the Hesperides?”
“Ah! must you go so soon?” they exclaimed. “You—that have
performed so many wonders, and spent such a toilsome life—cannot
you content yourself to repose a little while on the margin of this
peaceful river?”
Hercules shook his head.
“I must depart now,” said he.
“We will then give you the best directions we can,” replied the
damsels. “You must go to the seashore, and find out the Old One,
and compel him to inform you where the golden apples are to be
found.”
“The Old One!” repeated Hercules, laughing at this odd name.
“And, pray, who may the Old One be?”
“Why, the Old Man of the Sea, to be sure!” answered one of the
damsels. “He has fifty daughters, whom some people call very
beautiful; but we do not think it proper to be acquainted with them,
because they have sea-green hair, and taper away like fishes. You
must talk with this Old Man of the Sea. He is a seafaring person, and
knows all about the garden of the Hesperides; for it is situated in an
island which he is often in the habit of visiting.”
Hercules then asked whereabouts the Old One was most likely to
be met with. When the damsels had informed him, he thanked them
for all their kindness—for the bread and grapes with which they had
fed him, the lovely flowers with which they had crowned him, and
the songs and dances wherewith they had done him honor—and he
thanked them, most of all, for telling him the right way—and
immediately set forth upon his journey.
But before he was out of hearing, one of the maidens called after
him.
“Keep fast hold of the Old One, when you catch him!” cried she,
smiling and lifting her finger to make the caution more impressive.
“Do not be astonished at anything that may happen. Only hold him
fast, and he will tell you what you wish to know.”
Hercules again thanked her, and pursued his way, while the
maidens resumed their pleasant labor of making flower-wreaths.
They talked about the hero, long after he was gone.
“We will crown him with the loveliest of our garlands,” said they,
“when he returns hither with the three golden apples, after slaying
the dragon with a hundred heads.”
Meanwhile, Hercules travelled constantly onward, over hill and
dale, and through the solitary woods. Sometimes he swung his club
aloft, and splintered a mighty oak with a downright blow. His mind
was so full of the giants and monsters with whom it was the
business of his life to fight, that perhaps he mistook the great tree
for a giant or a monster. And so eager was Hercules to achieve what
he had undertaken, that he almost regretted to have spent so much
time with the damsels, wasting idle breath upon the story of his
adventures.
But thus it always is with persons who are destined to perform
great things. What they have already done seems less than nothing.
What they have taken in hand to do seems worth toil, danger, and
life itself.
Persons who happened to be passing through the forest must
have been affrighted to see him smite the trees with his great club.
With but a single blow, the trunk was riven as by the stroke of
lightning, and the broad boughs came rustling and crashing down.
Hastening forward, without ever pausing or looking behind, he by
and by heard the sea roaring at a distance. At this sound, he
increased his speed, and soon came to a beach, where the great
surf-waves tumbled themselves upon the hard sand, in a long line of
snowy foam. At one end of the beach, however, there was a
pleasant spot, where some green shrubbery clambered up a cliff,
making its rocky face look soft and beautiful. A carpet of verdant
grass, largely intermixed with sweet-smelling clover, covered the
narrow space between the bottom of the cliff and the sea. And what
should Hercules espy there, but an old man, fast asleep!
But was it really and truly an old man? Certainly, at first sight, it
looked very like one; but on closer inspection, it rather seemed to be
some kind of a creature that lived in the sea. For, on his legs and
arms there were scales, such as fishes have; he was web-footed and
web-fingered, after the fashion of a duck; and his long beard, being
of a greenish tinge, had more the appearance of a tuft of seaweed
than of an ordinary beard. Have you never seen a stick of timber,
that has been long tossed about by the waves, and has got all
overgrown with barnacles, and, at last drifting ashore, seems to
have been thrown up from the very deepest bottom of the sea?
Well, the old man would have put you in mind of just such a wave-
tost spar! But Hercules, the instant he set eyes on this strange
figure, was convinced that it could be no other than the Old One,
who was to direct him on his way.
Yes, it was the selfsame Old Man of the Sea whom the hospitable
maidens had talked to him about. Thanking his stars for the lucky
accident of finding the old fellow asleep, Hercules stole on tiptoe
towards him, and caught him by the arm and leg.
“Tell me,” cried he, before the Old One was well awake, “which is
the way to the garden of the Hesperides.”
As you may easily imagine, the Old Man of the Sea awoke in a
fright. But his astonishment could hardly have been greater than
was that of Hercules, the next moment. For, all of a sudden, the Old
One seemed to disappear out of his grasp, and he found himself
holding a stag by the fore and hind leg! But still he kept fast hold.
Then the stag disappeared, and in its stead there was a sea-bird,
fluttering and screaming, while Hercules clutched it by the wing and
claw! But the bird could not get away. Immediately afterwards, there
was an ugly three-headed dog, which growled and barked at
Hercules, and snapped fiercely at the hands by which he held him!
But Hercules would not let him go. In another minute, instead of the
three-headed dog, what should appear but Geryon, the six-legged
man-monster, kicking at Hercules with five of his legs, in order to get
the remaining one at liberty! But Hercules held on. By and by, no
Geryon was there, but a huge snake, like one of those which
Hercules had strangled in his babyhood, only a hundred times as
big; and it twisted and twined about the hero’s neck and body, and
threw its tail high into the air, and opened its deadly jaws as if to
devour him outright; so that it was really a very terrible spectacle!
But Hercules was no whit disheartened, and squeezed the great
snake so tightly that he soon began to hiss with pain.
You must understand that the Old Man of the Sea, though he
generally looked so much like the wave-beaten figurehead of a
vessel, had the power of assuming any shape he pleased. When he
found himself so roughly seized by Hercules, he had been in hopes
of putting him into such surprise and terror, by these magical
transformations, that the hero would be glad to let him go. If
Hercules had relaxed his grasp, the Old One would certainly have
plunged down to the very bottom of the sea, whence he would not
soon have given himself the trouble of coming up, in order to
answer any impertinent questions. Ninety-nine people out of a
hundred, I suppose, would have been frightened out of their wits by
the very first of his ugly shapes, and would have taken to their heels
at once. For one of the hardest things in this world is to see the
difference between real dangers and imaginary ones.
But, as Hercules held on so stubbornly, and only squeezed the Old
One so much the tighter at every change of shape, and really put
him to no small torture, he finally thought it best to reappear in his
own figure. So there he was again, a fishy, scaly, web-footed sort of
personage, with something like a tuft of seaweed at his chin.
“Pray, what do you want with me?” cried the Old One as soon as
he could take breath; for it is quite a tiresome affair to go through
so many false shapes. “Why do you squeeze me so hard? Let me go,
this moment, or I shall begin to consider you an extremely uncivil
person!”
“My name is Hercules!” roared the mighty stranger. “And you will
never get out of my clutch, until you tell me the nearest way to the
garden of the Hesperides!”
When the old fellow heard who it was that had caught him, he
saw, with half an eye, that it would be necessary to tell him
everything that he wanted to know. The Old One was an inhabitant
of the sea, you must recollect, and roamed about everywhere, like
other seafaring people. Of course, he had often heard of the fame of
Hercules, and of the wonderful things that he was constantly
performing, in various parts of the earth, and how determined he
always was to accomplish whatever he undertook. He therefore
made no more attempts to escape, but told the hero how to find the
garden of the Hesperides, and likewise warned him of many
difficulties which must be overcome, before he could arrive thither.
“You must go on, thus and thus,” said the Old Man of the Sea,
after taking the points of the compass, “till you come in sight of a
very tall giant, who holds the sky on his shoulders. And the giant, if
he happens to be in the humor, will tell you exactly where the
garden of the Hesperides lies.”
“And if the giant happens not to be in the humor,” remarked
Hercules, balancing his club on the tip of his finger, “perhaps I shall
find means to persuade him!”
Thanking the Old Man of the Sea, and begging his pardon for
having squeezed him so roughly, the hero resumed his journey. He
met with a great many strange adventures, which would be well
worth your hearing, if I had leisure to narrate them as minutely as
they deserve.
It was in this journey, if I mistake not, that he encountered a
prodigious giant, who was so wonderfully contrived by nature, that
every time he touched the earth, he became ten times as strong as
ever he had been before. His name was Antæus. You may see,
plainly enough, that it was a very difficult business to fight with such
a fellow; for, as often as he got a knock-down blow, up he started
again, stronger, fiercer, and abler to use his weapons than if his
enemy had let him alone. Thus, the harder Hercules pounded the
giant with his club, the further he seemed from winning the victory. I
have sometimes argued with such people, but never fought with
one. The only way in which Hercules found it possible to finish the
battle was by lifting Antæus off his feet into the air, and squeezing,
and squeezing, and squeezing him, until, finally, the strength was
quite squeezed out of his enormous body.
When this affair was finished, Hercules continued his travels, and
went to the land of Egypt, where he was taken prisoner, and would
have been put to death, if he had not slain the king of the country,
and made his escape. Passing through the deserts of Africa, and
going as fast as he could, he arrived at last on the shore of the great
ocean. And here, unless he could walk on the crests of the billows, it
seemed as if his journey must needs be at an end.
Nothing was before him, save the foaming, dashing, measureless
ocean. But, suddenly, as he looked towards the horizon, he saw
something, a great way off, which he had not seen the moment
before. It gleamed very brightly, almost as you may have beheld the
round, golden disk of the sun, when it rises or sets over the edge of
the world. It evidently drew nearer; for, at every instant, this
wonderful object became larger and more lustrous. At length, it had
come so nigh that Hercules discovered it to be an immense cup or
bowl, made either of gold or burnished brass. How it had got afloat
upon the sea is more than I can tell you. There it was, at all events,
rolling on the tumultuous billows, which tossed it up and down, and
heaved their foamy tops against its sides, but without ever throwing
their spray over the brim.
“I have seen many giants, in my time,” thought Hercules, “but
never one that would need to drink his wine out of a cup like this!”
And, true enough, what a cup it must have been! It was as large—
as large—but, in short, I am afraid to say how immeasurably large it
was. To speak within bounds, it was ten times larger than a great
mill-wheel; and, all of metal as it was, it floated over the heaving
surges more lightly than an acorn-cup adown the brook. The waves
tumbled it onward, until it grazed against the shore, within a short
distance of the spot where Hercules was standing.
As soon as this happened, he knew what was to be done; for he
had not gone through so many remarkable adventures without
learning pretty well how to conduct himself, whenever anything
came to pass a little out of the common rule. It was just as clear as
daylight that this marvellous cup had been set adrift by some
unseen power, and guided hitherward, in order to carry Hercules
across the sea, on his way to the garden of the Hesperides.
Accordingly, without a moment’s delay, he clambered over the brim,
and slid down on the inside, where, spreading out his lion’s skin, he
proceeded to take a little repose. He had scarcely rested, until now,
since he bade farewell to the damsels on the margin of the river. The
waves dashed, with a pleasant and ringing sound, against the
circumference of the hollow cup; it rocked lightly to and fro, and the
motion was so soothing that it speedily rocked Hercules into an
agreeable slumber.
His nap had probably lasted a good while, when the cup chanced
to graze against a rock, and, in consequence, immediately
resounded and reverberated through its golden or brazen substance,
a hundred times as loudly as ever you heard a church-bell. The noise
awoke Hercules, who instantly started up and gazed around him,
wondering whereabouts he was. He was not long in discovering that
the cup had floated across a great part of the sea, and was
approaching the shore of what seemed to be an island. And, on that
island, what do you think he saw?
No; you will never guess it, not if you were to try fifty thousand
times! It positively appears to me that this was the most marvellous
spectacle that had ever been seen by Hercules, in the whole course
of his wonderful travels and adventures. It was a greater marvel
than the hydra with nine heads, which kept growing twice as fast as
they were cut off; greater than the six-legged man-monster; greater
than Antæus; greater than anything that was ever beheld by
anybody, before or since the days of Hercules, or than anything that
remains to be beheld, by travellers in all time to come. It was a
giant!
But such an intolerably big giant. A giant as tall as a mountain; so
vast a giant, that the clouds rested about his midst, like a girdle, and
hung like a hoary beard from his chin, and flitted before his huge
eyes, so that he could neither see Hercules nor the golden cup in
which he was voyaging. And, most wonderful of all, the giant held
up his great hands and appeared to support the sky, which, so far as
Hercules could discern through the clouds, was resting upon his
head! This does really seem almost too much to believe.
Meanwhile, the bright cup continued to float onward, and finally
touch the strand. Just then a breeze wafted away the clouds from
before the giant’s visage, and Hercules beheld it, with all its
enormous features; eyes each of them as big as yonder lake, a nose
a mile long, and a mouth of the same width. It was a countenance
terrible from its enormity of size, but disconsolate and weary, even
as you may see the faces of many people, nowadays, who are
compelled to sustain burdens above their strength. What the sky
was to the giant, such are the cares of earth to those who let
themselves be weighed down by them. And whenever men
undertake what is beyond the just measure of their abilities, they
encounter precisely such a doom as had befallen this poor giant.
Poor fellow! He had evidently stood there a long while. An ancient
forest had been growing and decaying around his feet; and oak-
trees, of six or seven centuries old, had sprung from the acorn, and
forced themselves between his toes.
The giant now looked down from the far height of his great eyes,
and, perceiving Hercules, roared out, in a voice that resembled
thunder, proceeding out of the cloud that had just flitted away from
his face.
“Who are you, down at my feet there? And whence do you come,
in that little cup?”
“I am Hercules!” thundered back the hero, in a voice pretty nearly
or quite as loud as the giant’s own. “And I am seeking for the
garden of the Hesperides!”
“Ho! ho! ho!” roared the giant, in a fit of immense laughter. “That
is a wise adventure truly!”
“And why not?” cried Hercules, getting a little angry at the giant’s
mirth. “Do you think I am afraid of the dragon with a hundred
heads!”
Just at this time, while they were talking together, some black
clouds gathered about the giant’s middle, and burst into a
tremendous storm of thunder and lightning, causing such a pother
that Hercules found it impossible to distinguish a word. Only the
giant’s immeasurable legs were to be seen, standing up into the
obscurity of the tempest; and, now and then, a momentary glimpse
of his whole figure, mantled in a volume of mist. He seemed to be
speaking, most of the time; but his big, deep, rough voice chimed in
with the reverberations of the thunder-claps, and rolled away over
the hills, like them. Thus, by talking out of season, the foolish giant
expended an incalculable quantity of breath, to no purpose; for the
thunder spoke quite as intelligibly as he.
At last, the storm swept over, as suddenly as it had come. And
there again was the clear sky, and the weary giant holding it up, and
the pleasant sunshine beaming over his vast height, and illuminating
it against the background of the sullen thunderclouds. So far above
the shower had been his head, that not a hair of it was moistened
by the rain-drops!
When the giant could see Hercules still standing on the seashore,
he roared out to him anew.
“I am Atlas, the mightiest giant in the world! And I hold the sky
upon my head!”
“So I see,” answered Hercules. “But, can you show me the way to
the garden of the Hesperides?”
“What do you want there?” asked the giant.
“I want three of the golden apples,” shouted Hercules, “for my
cousin, the king.”
“There is nobody but myself,” quoth the giant, “that can go to the
garden of the Hesperides, and gather the golden apples. If it were
not for this little business of holding up the sky, I would make half a
dozen steps across the sea, and get them for you.”
“You are very kind,” replied Hercules. “And cannot you rest the sky
upon a mountain?”
“None of them are quite high enough,” said Atlas, shaking his
head. “But, if you were to take your stand on the summit of that
nearest one, your head would be pretty nearly on a level with mine.
You seem to be a fellow of some strength. What if you should take
my burden on your shoulders, while I do your errand for you?”
Hercules, as you must be careful to remember, was a remarkably
strong man; and though it certainly requires a great deal of
muscular power to uphold the sky, yet, if any mortal could be
supposed capable of such an exploit, he was the one. Nevertheless,
it seemed so difficult an undertaking, that, for the first time in his
life, he hesitated.
“Is the sky very heavy?” he inquired.
“Why, not particularly so, at first,” answered the giant, shrugging
his shoulders. “But it gets to be a little burdensome, after a
thousand years!”
“And how long a time,” asked the hero, “will it take you to get the
golden apples?”
“Oh, that will be done in a few moments,” cried Atlas. “I shall take
ten or fifteen miles at a stride, and be at the garden and back again
before your shoulders begin to ache.”
“Well, then,” answered Hercules, “I will climb the mountain behind
you there, and relieve you of your burden.”
The truth is, Hercules had a kind heart of his own, and considered
that he should be doing the giant a favor, by allowing him this
opportunity for a ramble. And, besides, he thought that it would be
still more for his own glory, if he could boast of upholding the sky,
than merely to do so ordinary a thing as to conquer a dragon with a
hundred heads. Accordingly, without more words, the sky was
shifted from the shoulders of Atlas, and placed upon those of
Hercules.
When this was safely accomplished, the first thing that the giant
did was to stretch himself; and you may imagine what a prodigious
spectacle he was then. Next, he slowly lifted one of his feet out of
the forest that had grown up around it; then, the other. Then, all at
once, he began to caper, and leap, and dance, for joy at his
freedom; flinging himself nobody knows how high into the air, and
floundering down again with a shock that made the earth tremble.
Then he laughed—Ho! ho! ho!—with a thunderous roar that was
echoed from the mountains, far and near, as if they and the giant
had been so many rejoicing brothers. When his joy had a little
subsided, he stepped into the sea; ten miles at the first stride, which
brought him mid-leg deep; and ten miles at the second, when the
water came just above his knees; and ten miles more at the third, by
which he was immersed nearly to his waist. This was the greatest
depth of the sea.
Hercules watched the giant, as he still went onward; for it was
really a wonderful sight, this immense human form, more than thirty
miles off, half hidden in the ocean, but with his upper half as tall,
and misty, and blue, as a distant mountain. At last the gigantic
shape faded entirely out of view. And now Hercules began to
consider what he should do, in case Atlas should be drowned in the
sea, or if he were to be stung to death by the dragon with the
hundred heads, which guarded the golden apples of the Hesperides.
If any such misfortune were to happen, how could he ever get rid of
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like