Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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 - Fourth Edition

You're reading from   Learning jQuery - Fourth Edition Add to your current website development skills with this brilliant guide to JQuery. This step by step course needs little prior JavaScript knowledge so is suitable for beginners and more seasoned developers alike.

Arrow left icon
Product type Paperback
Published in Jun 2013
Publisher Packt
ISBN-13 9781782163145
Length 444 pages
Edition 4th Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (24) Chapters Close

Learning jQuery Fourth 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

DOM traversal methods


After creating a jQuery object using $(), we can alter the set of matched elements we are working with by calling one of these DOM traversal methods. DOM traversal methods are discussed in detail in Chapter 2, Selecting Elements.

Filtering

Traversal method

Returns a jQuery object containing…

.filter(selector)

Selected elements that match the given selector.

.filter(callback)

Selected elements for which the callback function returns true.

.eq(index)

The selected element at the given 0-based index.

.first()

The first selected element.

.last()

The final selected element.

.slice(start, [end])

Selected elements in the given range of 0-based indices.

.not(selector)

Selected elements that do not match the given selector.

.has(selector)

Selected elements that have a descendant matching selector.

Descendants

Traversal method

Returns a jQuery object containing…

.find(selector)

Descendant elements that match the selector.

.contents()

Child nodes (including text nodes).

.children([selector])

Child nodes, optionally filtered by a selector.

Siblings

Traversal method

Returns a jQuery object containing…

.next([selector])

The sibling immediately following each selected element, optionally filtered by a selector.

.nextAll([selector])

All siblings following each selected element, optionally filtered by a selector.

.nextUntil([selector], [filter])

All siblings following each selected element up to and not including the first element matching selector, optionally filtered by an additional selector.

.prev([selector])

The sibling immediately preceding each selected element, optionally filtered by a selector.

.prevAll([selector])

All siblings preceding each selected element, optionally filtered by a selector.

.prevUntil([selector], [filter])

All siblings preceding each selected element up to and not including the first element matching selector, optionally filtered by an additional selector.

.siblings([selector])

All siblings, optionally filtered by a selector.

Ancestors

Traversal method

Returns a jQuery object containing…

.parent([selector])

The parent of each selected element, optionally filtered by a selector.

.parents([selector])

All ancestors, optionally filtered by a selector.

.parentsUntil([selector], [filter])

All ancestors of each selected element up to and not including the first element matching selector, optionally filtered by an additional selector.

.closest(selector)

The first element that matches the selector, starting at the selected element and moving up through its ancestors in the DOM tree.

.offsetParent()

The positioned parent, either relative or absolute of the first selected element.

Collection manipulation

Traversal method

Returns a jQuery object containing…

.add(selector)

The selected elements, plus any additional elements that match the given selector.

.addBack()

The selected elements, plus the previous set of selected elements on the internal jQuery stack.

.end()

The previous set of selected elements on the internal jQuery stack.

.map(callback)

The result of the callback function when called on each selected element.

.pushStack(elements)

The specified elements.

Working with selected elements

Traversal method

Description

.is(selector)

Determines whether any matched element is matched by the given selector expression.

.index()

Gets the index of the matched element in relation to its siblings.

.index(element)

Gets the index of the given DOM node within the set of matched elements.

$.contains(a, b)

Determines whether DOM node b contains DOM node a.

.each(callback)

Iterates over the matched elements, executing callback for each element.

.length

Gets the number of matched elements.

.get()

Gets an array of DOM nodes corresponding to the matched elements.

.get(index)

Gets the DOM node corresponding to the matched element at the given index.

.toArray()

Gets an array of DOM nodes corresponding to the matched elements.

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