Selection and chaining
Wrap elements, filter collections and chain operations.
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.
const cards = $('.card')
cards.filter('.is-featured').addClass('is-highlighted')
cards.find('a').attr('target', '_blank')Your turn
EasySelect and add a class
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 inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.