FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

15 snippets foundClear filters
jQueryTraversal & selection

Collect matching ancestors

jQuery: parents can return several ancestors, ordered from the nearest outward.

jQuery✓ Tested
jQueryTraversal & selection

Filter a selection

Reduce a jQuery selection to elements with a matching class.

jQuery✓ Tested
jQueryTraversal & selection

Find descendants

Select only matching descendants of a jQuery container.

jQuery✓ Tested
jQueryTraversal & selection

Find the nearest matching ancestor

Read a parent row attribute using jQuery closest.

jQuery✓ Tested
jQueryTraversal & selection

Read checked options

Collect checked checkbox values with jQuery map and get.

jQuery✓ Tested
jQueryTraversal & selection

Return to the previous collection in a chain

jQuery: end restores the selection before the last traversal operation.

jQuery✓ Tested
jQueryTraversal & selection

Select a range from a collection

jQuery: slice includes the start index and excludes the end index.

jQuery✓ Tested
jQueryTraversal & selection

Select an element by zero-based position

jQuery: eq returns a jQuery collection containing the selected index.

jQuery✓ Tested
jQueryTraversal & selection

Select an immediate parent

jQuery: parent moves exactly one level up the DOM.

jQuery✓ Tested
jQueryTraversal & selection

Select direct children without deeper descendants

jQuery: children limits matching to one level.

jQuery✓ Tested
jQueryTraversal & selection

Select siblings up to a boundary

jQuery: nextUntil excludes the boundary element itself.

jQuery✓ Tested
jQueryTraversal & selection

Select siblings while excluding the current element

jQuery: siblings selects other children of the same parent.

jQuery✓ Tested