Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning jQuery, Third Edition

You're reading from   Learning jQuery, Third Edition Create better interaction, design, and web development with simple JavaScript techniques

Arrow left icon
Product type Paperback
Published in Sep 2011
Publisher Packt
ISBN-13 9781849516549
Length 428 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (24) Chapters Close

Learning jQuery Third Edition
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started FREE CHAPTER 2. Selecting Elements 3. Handling Events 4. Styling and Animating 5. Manipulating the DOM 6. Sending Data with Ajax 7. Using Plugins 8. Developing Plugins 9. Advanced Selectors and Traversing 10. Advanced Events 11. Advanced Effects 12. Advanced DOM Manipulation 13. Advanced Ajax JavaScript Closures Testing JavaScript with QUnit Quick Reference 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, Selecting Elements.

Simple CSS

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 sibling elements a

a ~ b

Elements b that follow sibling elements a

Position among siblings

Selector

Matches

: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

Position among matched elements

Selector

Matches

: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)

Attributes

Selector

Matches

[attr]

Elements that have the attribute attr

[attr="value"]

Elements whose attr attribute are value

[attr!="value"]

Elements whose attr attribute are not value

[attr^="value"]

Elements whose attr attribute begin with value

[attr$="value"]

Elements whose attr attribute end with value

[attr*="value"]

Elements whose attr attribute contain the substring value

[attr~="value"]

Elements whose attr attribute is a space-delimited set of strings, one of which is value

[attr|="value"]

Elements whose attr attribute is either equal to value or begins with value followed by a hyphen

Forms

Selector

Matches

:input

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

:text

<input> elements with type="text"

:password

<input> elements with type="password"

:file

<input> elements with type="file"

: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

:enabled

Enabled form elements

:disabled

Disabled form elements

:checked

Checked checkboxes and radio buttons

:selected

Selected <option> elements

Other custom selectors

Selector

Matches

: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

:focus

The element that has the keyboard focus

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image