Book Image

Learning jQuery 1.3

By : Jonathan Chaffer, Karl Swedberg
Book Image

Learning jQuery 1.3

By: Jonathan Chaffer, Karl Swedberg

Overview of this book

<p>To build interesting, interactive sites, developers are turning to JavaScript libraries such as jQuery to automate common tasks and simplify complicated ones. Because many web developers have more experience with HTML and CSS than with JavaScript, the library's design lends itself to a quick start for designers with little programming experience. Experienced programmers will also be aided by its conceptual consistency. <br /><br />Revised and updated for version 1.3 of jQuery, this book teaches you the basics of jQuery for adding interactions and animations to your pages. Even if previous attempts at writing JavaScript have left you baffled, this book will guide you past the pitfalls associated with AJAX, events, effects, and advanced JavaScript language features.<br /><br />In this book, the authors share their knowledge, experience, and enthusiasm about jQuery to help you get the most from the library and to make your web applications shine. The book introduces jQuery and shows how you can write a functioning jQuery program in just three lines of code. It then guides you through CSS selectors and shows how to enhance the basic event handling mechanisms to give them a more elegant syntax. You will then learn to add impact to your actions through a set of simple visual effects and also to create, copy, reassemble, and embellish content using jQuery's DOM modification methods. You will also learn to send and retrieve information with AJAX methods. The book will then step you through many detailed, real-world examples and even equip you to extend the jQuery library itself with your own plug-ins.</p>
Table of Contents (22 chapters)
Learning jQuery 1.3
Credits
Foreword
About the Authors
About the Reviewers
Preface
Index

Selector expressions


The jQuery factory function $() is used to find elements on the page to work with. This function takes a string composed of CSS-like syntax, called a selector expression. Selector expressions are discussed in detail in Chapter 2.

Selector

Matches

*

All elements.

#id

The element with the given ID.

element

All elements of the given type.

.class

All elements with the given class.

a, b

Elements that are matched by a or b.

a b

Elements b that are descendants of a.

a > b

Elements b that are children of a.

a + b

Elements b that immediately follow a.

a ~ b

Elements b that are siblings of a.

:first

The first element in the result set.

:last

The last element in the result set.

:not(a)

All elements in the result set that are not matched by a.

:even

Even elements in the result set (0-based).

:odd

Odd elements in the result set (0-based).

:eq(index)

A numbered element in the result set (0-based).

:gt(index)

All elements in the result set after (greater than) the given index (0-based).

:lt(index)

All elements in the result set before (less than) the given index (0-based).

:header

Header elements (e.g. <h1>, <h2>).

:animated

Elements with an animation in progress.

:contains(text)

Elements containing the given text.

:empty

Elements with no child nodes.

:has(a)

Elements containing a descendant element matching a.

:parent

Elements that have child nodes.

:hidden

Elements that are hidden, either through CSS or because they are <input type="hidden" />.

:visible

The inverse of :hidden.

[attr]

Elements that have the attribute attr.

[attr=value]

Elements whose attr attribute is value.

[attr!=value]

Elements whose attr attribute is not value.

[attr^=value]

Elements whose attr attribute begins with value.

[attr$=value]

Elements whose attr attribute ends with value.

[attr*=value]

Elements whose attr attribute contains the substring value.

:nth-child(index)

Elements which are the indexth child of their parent element (1-based).

:nth-child(even)

Elements which are an even child of their parent element (1-based).

:nth-child(odd)

Elements which are an odd child of their parent element (1-based).

:nth-child(formula)

Elements which are the nth child of their parent element (1-based). Formulas are of the form an+b for integers a and b.

:first-child

Elements which are the first child of their parent.

:last-child

Elements which are the last child of their parent.

:only-child

Elements which are the only child of their parent.

:input

All <input>, <select>, <textarea>, and <button> elements.

:text

<input> elements with type="text".

:password

<input> elements with type="password".

:radio

<input> elements with type="radio".

:checkbox

<input> elements with type="checkbox".

:submit

<input> elements with type="submit".

:image

<input> elements with type="image".

:reset

<input> elements with type="reset".

:button

<input> elements with type="button", and <button> elements.

:file

<input> elements with type="file".

:enabled

Enabled form elements.

:disabled

Disabled form elements.

:checked

Checked checkboxes and radio buttons.

:selected

Selected <option> elements.