
Enter a search term above to see results...
Enter a search term above to see results...
The DOM Traversal methods allow you to get from one element to another based off their relationship. Query supports piercing shadow DOM boundaries when using $$
Finds descendant elements that match the specified selector.
$('selector').find(childSelector)
Name | Type | Description |
---|---|---|
childSelector | string | A selector to match descendant elements |
Query object containing the matched elements.
// Find all paragraphs within a div$('div').find('p').addClass('highlight');
$$('my-component').find('p').addClass('highlight');
Gets the parent of each element in the current set of matched elements.
$('selector').parent(parentSelector)
Name | Type | Description |
---|---|---|
parentSelector | string | (Optional) A selector to filter parent elements |
Query object containing the parent elements.
// Get the parent of a button$('button').parent().addClass('button-group');
$$('my-component menu-item').parent().addClass('menu-styling');
Gets the children of each element in the set of matched elements.
$('selector').children(childSelector)
Name | Type | Description |
---|---|---|
childSelector | string | (Optional) A selector to filter children elements |
Query object containing the child elements.
// Get all direct child list items of an unordered list$('ul').children('li').css('color', 'red');
Gets the siblings of each element in the set of matched elements.
$('selector').siblings(siblingSelector)
Name | Type | Description |
---|---|---|
siblingSelector | string | (Optional) A selector to filter sibling elements |
Query object containing the sibling elements.
// Get all siblings of a selected element$('.selected').siblings().addClass('dimmed');
$$('my-component').find('.shadow-selected').siblings().addClass('shadow-dimmed');
Finds the closest ancestor element that matches the selector.
$('selector').closest(ancestorSelector)
Name | Type | Description |
---|---|---|
ancestorSelector | string | A selector to match ancestor elements |
Query object containing the closest matching ancestor.
// Find the closest form ancestor$('input').closest('form').submit();
$$('my-component').find('input').closest('.shadow-form').addClass('validated');
Gets the immediately following sibling of each element in the set of matched elements.
$('selector').next(nextSelector)
Name | Type | Description |
---|---|---|
nextSelector | string | (Optional) A selector to filter the next element |
Query object containing the next sibling elements.
// Get the next sibling of a paragraph$('p').next().css('margin-top', '20px');
$$('my-component').find('.shadow-paragraph').next().css('margin-top', '10px');
Gets the immediately preceding sibling of each element in the set of matched elements.
$('selector').prev(prevSelector)
Name | Type | Description |
---|---|---|
prevSelector | string | (Optional) A selector to filter the previous element |
Query object containing the previous sibling elements.
// Get the previous sibling of a heading$('h2').prev().css('color', 'red');
$$('my-component').find('.shadow-heading').prev().css('margin-bottom', '5px');