jQuery·jQuery from selection to migration

Selection and chaining

Wrap elements, filter collections and chain operations.

Beginner 12 min read Lesson 2 of 300 Challenge included
What you will be able to do
  • Use $() with a CSS selector.
  • Chain methods that return the collection.
  • Use .find for descendants and .filter for the current set.
  • Cache selections instead of repeating them.

In plain English

The $ function returns a jQuery collection. Most methods return the same collection, which is why chaining works. Select with CSS, then narrow with .filter, .find or .eq.

select.jsJavaScript
const cards = $('.card')
cards.filter('.is-featured').addClass('is-highlighted')
cards.find('a').attr('target', '_blank')
Your turn

Select and add a class

Easy

Add the class active to the element with id hero.

JAVASCRIPT · starter
$()
Check your understanding before moving on.
Knowledge checkQuestion 1

Why does chaining work in jQuery?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: DOM manipulation
Lesson 2 of 300 · 0% of course