← Back to Index

.children()

Get the children of each element in the set of matched elements, optionally filtered by a selector.

Examples

1. Get all children

const $kids = $('ul').children();

Result

// SR Object containing all direct <li> children
[ <li>Item 1</li>, <li>Item 2</li> ]

2. Get filtered children

const $active = $('ul').children('.active');

Result

// SR Object containing only matching children
[ <li class="active">Item 2</li> ]

Parameters

Parameter Type Description
selector string Optional. A string containing a selector expression to match elements against.

Returns: A new SR object.