The snippet library.
Small, practical examples. Search by task or narrow things down below.
Collect matching ancestors
jQuery: parents can return several ancestors, ordered from the nearest outward.
jQuery✓ Tested
Filter a selection
Reduce a jQuery selection to elements with a matching class.
jQuery✓ Tested
Find descendants
Select only matching descendants of a jQuery container.
jQuery✓ Tested
Find the nearest matching ancestor
Read a parent row attribute using jQuery closest.
jQuery✓ Tested
Read checked options
Collect checked checkbox values with jQuery map and get.
jQuery✓ Tested
Return to the previous collection in a chain
jQuery: end restores the selection before the last traversal operation.
jQuery✓ Tested
Select a range from a collection
jQuery: slice includes the start index and excludes the end index.
jQuery✓ Tested
Select an element by zero-based position
jQuery: eq returns a jQuery collection containing the selected index.
jQuery✓ Tested
Select an immediate parent
jQuery: parent moves exactly one level up the DOM.
jQuery✓ Tested
Select direct children without deeper descendants
jQuery: children limits matching to one level.
jQuery✓ Tested
Select siblings up to a boundary
jQuery: nextUntil excludes the boundary element itself.
jQuery✓ Tested
Select siblings while excluding the current element
jQuery: siblings selects other children of the same parent.
jQuery✓ Tested