jQuery 1 4 Reference Guide 1st Edition Karl Swedberg instant download
jQuery 1 4 Reference Guide 1st Edition Karl Swedberg instant download
https://ebookname.com/product/jquery-1-4-reference-guide-1st-
edition-karl-swedberg/
https://ebookname.com/product/jquery-pocket-reference-1st-
edition-david-flanagan/
https://ebookname.com/product/jquery-cookbook-solutions-examples-
for-jquery-developers-animal-guide-1st-edition-cody-lindley-2/
https://ebookname.com/product/jquery-cookbook-solutions-examples-
for-jquery-developers-animal-guide-1st-edition-cody-lindley/
https://ebookname.com/product/java-server-pages-1st-edition-hans-
bergsten/
Political Regime and Summary of Plato s Laws The
Political Writings II 1st Edition Alfarabi
https://ebookname.com/product/political-regime-and-summary-of-
plato-s-laws-the-political-writings-ii-1st-edition-alfarabi/
https://ebookname.com/product/christmas-let-s-see-library-
natalie-m-rosinsky/
https://ebookname.com/product/learning-communities-from-start-to-
finish-new-directions-for-student-services-number-149-1st-
edition-mimi-benjamin/
https://ebookname.com/product/the-vertical-transportation-
handbook-fourth-edition-george-r-strakosch/
https://ebookname.com/product/cicero-pro-caelio-3rd-edition-
marcus-tullius-cicero/
Key Topics in General Surgery 2Rev Ed Edition Lattimer
R
https://ebookname.com/product/key-topics-in-general-surgery-2rev-
ed-edition-lattimer-r/
jQuery 1.4 Reference Guide
Karl Swedberg
Jonathan Chaffer
BIRMINGHAM - MUMBAI
jQuery 1.4 Reference Guide
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the authors, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-84951-004-2
www.packtpub.com
Acquisition Editor
Project Coordinator
Swapna V. Verlekar
Joel Goveya
Development Editor
Proofreader
Swapna V. Verlekar
Chris Smith
Technical Editor
Graphics
Tariq Rakhange
Nilesh R. Mohite
Copy Editor
Production Coordinator
Sneha Kulkarni
Dolly Dasilva
Indexer
Cover Work
Hemangini Bari
Dolly Dasilva
About the Authors
In the open source community, Jonathan has been very active in the Drupal CMS
project, which has adopted jQuery as its JavaScript framework of choice. He is the
creator of the Content Construction Kit, a popular module for managing structured
content on Drupal sites. He is responsible for major overhauls of Drupal's menu
system and developer API reference.
I would like to thank Jenny for her tireless enthusiasm and support,
Karl for the motivation to continue writing when the spirit was
weak, and the Ars Technica community for constant inspiration
toward technical excellence.
About the Reviewers
Dave holds both a bachelor's and a master's degree in Computer Science from the
University of Virginia. He has been active in the jQuery community since 2006 and
has written several popular plug-ins such as Splitter.
Table of Contents
Preface 1
Chapter 1: Anatomy of a jQuery Script 7
A dynamic table of contents 7
Obtaining jQuery 8
Setting up the HTML document 9
Writing the jQuery code 11
Script dissection 12
Selector expressions 12
DOM traversal methods 13
DOM manipulation methods 13
Event methods 14
Effect methods 14
AJAX methods 15
Miscellaneous methods 15
Plug-in API 16
Summary 16
Chapter 2: Selector Expressions 17
CSS selectors 17
Element (T) 17
ID (#myid) 18
Class (.myclass) 18
Descendant (E F) 19
Child (E > F) 20
Adjacent sibling (E + F) 20
General sibling (E ~ F) 21
Multiple expressions (E, F, G) 22
Numbered child (:nth-child(n/even/odd/expr)) 22
First child (:first-child) 24
Table of Contents
[ ii ]
Table of Contents
.slice() 49
Tree traversal methods 51
.find() 51
.children() 52
.parents() 53
.parentsUntil() 55
.parent() 56
.closest() 57
.offsetParent() 59
.siblings() 60
.prev() 61
.prevAll() 62
.prevUntil() 63
.next() 64
.nextAll() 65
.nextUntil() 66
Miscellaneous traversal methods 68
.add() 68
.is() 69
.end() 70
.andSelf() 72
.map() 73
.contents() 74
Chapter 4: DOM Manipulation Methods 77
General attributes 77
.attr() (getter) 77
.attr() (setter) 78
.removeAttr() 80
Style properties 80
.css() (getter) 80
.css() (setter) 81
.height() (getter) 82
.height() (setter) 83
.innerHeight() 84
.outerHeight() 84
.width() (getter) 85
.width() (setter) 86
.innerWidth() 87
.outerWidth() 87
.offset() (getter) 88
[ iii ]
Table of Contents
.offset() (setter) 89
.position() 89
.scrollTop() (getter) 90
.scrollTop() (setter) 90
.scrollLeft() (getter) 91
.scrollLeft() (setter) 91
Class attributes 91
.hasClass() 92
.addClass() 92
.removeClass() 93
.toggleClass() 95
DOM replacement 96
.html() (getter) 97
.html() (setter) 97
.text() (getter) 98
.text() (setter) 99
.val() (getter) 101
.val() (setter) 101
.replaceWith() 102
.replaceAll() 103
DOM insertion, inside 104
.prepend() 104
.prependTo() 106
.append() 108
.appendTo() 109
DOM insertion, outside 111
.before() 111
.insertBefore() 112
.after() 114
.insertAfter() 115
DOM insertion, around 117
.wrap() 117
.wrapAll() 118
.wrapInner() 119
DOM copying 121
.clone() 121
DOM removal 122
.empty() 122
.remove() 123
.detach() 125
.unwrap() 125
[ iv ]
Table of Contents
[v]
Table of Contents
[ vi ]
Table of Contents
[ vii ]
Table of Contents
[ viii ]
Preface
jQuery is a powerful, yet easy-to-use, JavaScript library that helps web developers
and designers add dynamic, interactive elements to their sites, smoothing out
browser inconsistencies and greatly reducing development time. In jQuery 1.4
Reference Guide, you can investigate this library's features in a thorough,
accessible format.
This book offers an organized menu of every jQuery method, function, and selector.
Entries are accompanied by detailed descriptions and helpful recipes that will assist
you in getting the most out of jQuery, and avoiding the pitfalls commonly associated
with JavaScript and other client-side languages. If you're still hungry for more, the
book shows you how to cook up your own extensions with jQuery's elegant
plug-in architecture.
You'll discover the untapped possibilities that jQuery makes available and hone
your skills as you return to this guide time and again.
The heart of the book is a set of reference chapters, which allow you to quickly
look up the details of any jQuery method. Chapter 2, Selector Expressions, lists every
available selector for finding page elements.
Chapter 3, DOM Traversal Methods, builds on the previous chapter with a catalog of
jQuery methods for finding page elements.
Chapter 5, Event Methods, details each event that can be triggered and reacted to
by jQuery.
Chapter 6, Effect Methods, defines the range of animations built into jQuery, as well as
the toolkit available for building your own.
Chapter 7, AJAX Methods, lists the ways in which jQuery can initiate and respond to
server communication without refreshing the page.
Chapter 9, jQuery Properties, lists properties of the jQuery object that can be inspected
for information about the browser environment.
With the catalog of built-in functionality concluded, we'll dive into the extension
mechanisms jQuery makes available. Chapter 10, Plug-in API, reveals these powerful
ways to enhance jQuery's already robust capabilities using a plug-in.
Chapter 11, Alphabetical Quick Reference, offers a handy list of all methods and
their arguments.
[2]
Preface
Conventions
In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.
Code words in text are shown as follows: "The .removeAttr() method uses the
JavaScript removeAttribute() function."
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8"/>
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.plug-in.js"
type="text/javascript"></script>
<script src="custom.js" type="text/javascript"></script>
<title>Example</title>
</head>
New terms and important words are shown in bold. Words that you see on the
screen, in menus or dialog boxes for example, appear in the text like this: "After this
code executes, clicks on Trigger the handler will also display the same message."
[3]
Preface
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or may have disliked. Reader feedback is important for us
to develop titles that you really get the most out of.
If there is a book that you need and would like to see us publish, please send
us a note in the SUGGEST A TITLE form on www.packtpub.com or email to
[email protected].
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
[4]
Preface
Errata
Although we have taken every care to ensure the accuracy of our content,
mistakes do happen. If you find a mistake in one of our books—maybe a mistake
in the text or the code—we would be grateful if you would report this to us.
By doing so, you can save other readers from frustration and help us to improve
subsequent versions of this book. If you find any errata, please report them by
visiting http://www.packtpub.com/support, selecting your book, clicking on
the let us know link, and entering the details of your errata. Once your errata are
verified, your submission will be accepted and the errata will be uploaded on
our web site, or added to any list of existing errata, under the Erarata section
of that title. Any existing errata can be viewed by selecting your title from
http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you
come across any illegal copies of our works, in any form, on the Internet, please
provide us with the location address or web site name immediately so that we can
pursue a remedy.
We appreciate your help in protecting our authors, and our ability to bring you
valuable content.
Questions
You can contact us at [email protected] if you are having a problem with
any aspect of the book, and we will do our best to address it.
[5]
Anatomy of a jQuery Script
A typical jQuery script uses a wide assortment of the methods that the library
offers. Selectors, DOM manipulation, event handling, and so forth come into play
as required by the task at hand. In order to make the best use of jQuery, it's good to
keep in mind the breadth of capabilities it provides.
This book will itemize every method and function found in the jQuery library. As
there are so many to sort through, it will be useful to know what the basic categories
of methods are and how they come to play within a jQuery script. Here we will see a
fully functioning script, and examine how the different aspects of jQuery are utilized
in each part of it.
We'll have it collapsed initially as shown, but a click will expand it to full height.
At the same time, we'll add a feature to the main body text. The introduction
of the text on the page will not be loaded initially, but when the user clicks on
Introduction, the intro text will be inserted in place from another file.
Before we reveal the script that performs these tasks, we should walk through the
environment in which the script resides.
Obtaining jQuery
The official jQuery web site (http://jquery.com/) is always the most up-to-date
resource for code and news related to the library. To get started, we need a copy
of jQuery, which can be downloaded right from the front page of the site. Several
versions of jQuery may be available at any given moment; the most appropriate for
us will be the latest uncompressed version. As of the writing of this book, the latest
version of jQuery is 1.4.
[8]
Exploring the Variety of Random
Documents with Different Content
love. She wrote me that she was to marry a Northerner, and when
she added his name—it was the son of the man who killed her
father.”
“It is not possible!” the other exclaimed. “You imagined it. Such
things happen in melodramas—”
She put up her hand and arrested his words.
“This happened not in a melodrama, but in a tragedy—in my life,”
she said. “I need not go into details. She married him, and I have
never seen her since.”
“Did he know?”
“No. It was my wedding gift to my daughter—that I kept her secret.
That was all I had strength to do. You think I was an unnatural
mother, of course; but—”
She saw that his eyes were moist as he raised them in answering.
“I should have said so yesterday without any hesitation; to-day—”
“To-day?” she echoed eagerly, as he paused.
“To-day,” he answered, letting his glance sweep over the pathetic
memorials so thick about them—“to-day at least I understand, and I
do not wonder.”
She looked at him with all her heart in her eyes, trying to read his
most hidden feeling. Then she touched his arm lightly with the tips
of her slender black-gloved fingers.
“Come,” she said.
She led him across the room, and pointed to a colonel’s sash and
pistols which lay in one of the cases under a faded card.
“Those were my husband’s.”
“Those!” he cried. “You Louise’s mother? It is impossible!”
“It may be impossible; but, as I said of the other thing, it is true.”
“The other thing?” he repeated. “What—do you mean the thing you
said—that my father and he— That cannot be true. I should surely
have known!”
“It is true,” she insisted. “At the moment it happened they were
surrounded by our soldiers, and his own men probably did not
realize just what happened. But I—I know every minute of that
fight! One of my husband’s staff had been at West Point with them
both, and he told me. He saw it, and tried to come between them.
Your wife married you, knowing you to be the son of the man who
killed her father.”
The Northerner passed his hand across his forehead as if to wipe
away the confusion of his mind. His eyes were cast down, but she
saw that their lids were wet.
“Poor Louise!” he murmured, seemingly rather to himself than to
her; “how she must have suffered over that secret. Poor Louise!”
“You come here,” Mrs. Desborough went on, feeling herself choke at
his words, but determined not to give way to the warmer impulse of
her heart, “and even you are moved by these sacred relics. What do
you think they are to us?”
She was half conscious that she was appealing to the memorials
around her to strengthen her in her purpose not to yield, not to
make peace with the son of the man who had slain her husband, her
hero, her love; she felt that in harboring for an instant such an
impulse she was untrue to the Cause which, though lost, was for her
forever living with the deathless devotion of love and anguish.
“These relics do move me,” her son-in-law said gently. “They move
me so deeply that they seem to me wrong. I confess that I was
thinking, before you came in, that if I were a Southerner, with the
traditions of the South behind me, and the bitter sense of failure to
embitter me, they would stir me to madness; that I should feel it
impossible ever to be loyal to anything but the South. The war is
over. The South at last is understood. She is honored for the
incredible bravery with which, under crushing odds, she fought for
her conviction. Why prolong the inevitable pain? Why gather these
relics to nourish a feeling absolutely untrue—the feeling that the
Union is less your country than it is ours?”
“Because it is just to the dead,” she answered swiftly. “Because it is
only justice that we keep in remembrance how true they were, how
gallant, how brave, how noble, and—O God!—that we make some
poor record of what we of the South have suffered!”
He shook his head and sighed. She saw the tears in his eyes and did
not attempt to hide her own.
“Would you have it forgotten,” she demanded passionately, “that the
grandfather of your son—the father of your wife—was one of God’s
noblemen? Would you have him remembered only as a beaten
rebel? I tell you that if we had not gathered these memorials, every
clod that was wet with their blood would cry out against us! In the
North you call these men rebels; there is no battlefield in the South
where the very rustle of the grass does not whisper over their graves
that they were patriots and heroes! And this, poor though it be”—
and she waved her hand to the cases around them—“is the best
memorial we can give them.”
He made a step forward, and held out both his hands impulsively.
She did not take them, and they dropped again. He hesitated, and
then drew back.
“It must be as it is,” he said sadly. “Even if I blamed you women of
the South, I could not say so here. Only,” he added, his voice falling,
“can you forget that the women of the North suffered too? I grew up
in the shadow of a grief so great that it sapped the very life of my
mother, and in the end killed her. Do you think I could visit that upon
the innocent head of Louise?—I did not mean, though, to speak of
myself, now that I know who you are. I will not intrude on you; but
my little son, with your husband’s name and his mother’s eyes, is
certainly guiltless. I will not come with him, but may I not send him
with my man to see you this afternoon, so that I may say to Louise
that you have kissed him and given him your blessing? Sorrow has
taken away his other grandmother.”
It seemed to her that she could not endure the speaking of one
syllable more. Her whole body trembled, and she raised her hands in
an impulsive gesture which implored him to be silent. All the old
mother-love for Louise, the passionate crying of her lonely heart for
this unseen grandson with the blood of her dead husband warm in
his veins, the grief of black years and fidelity to old ideals, warred
within her, and tore her like wolves. She cast a glance around as if to
find some way by which she could flee from this position which it
was too terrible to face. Then she saw her companion look at her
with infinite pity and sadness.
“Then,” he said, “I can only say good-by.”
But she sprang forward as if she burst from chains, and threw
herself upon his breast, the agony of the long, bitter past gushing in
a torrent of hot tears.
“Oh, my son! my son!” she sobbed.
By MARGARET SHERWOOD
MONTLIVET
By NORAH DAVIS
HOUGHTON BOSTON
MIFFLIN AND
& NEW
COMPANY YORK
Transcriber’s Note
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
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.
ebookname.com