Easy Tutorial
❮ Sel Onlychild Sel Multiple Classes ❯

jQuery parent() Method

jQuery Traversal Methods

Example

Return the direct parent of the <span> element:

Result:


Definition and Usage

The parent() method returns the direct parent of the selected element.

DOM Tree: This method only traverses a single level up the DOM tree. To traverse all the way up to the document root (returning grandparents or other ancestors), use the parents() or parentsUntil() methods.

Tip: To traverse a single level down the DOM tree, or all the way down to the last descendant (returning children or other descendants), use the children() or find() methods.


Syntax

Parameter Description
filter Optional. Specifies a selector expression to narrow down the search for parent elements.

More Examples

Return the direct parent of the <span> element

Narrow down the search scope

Return the <div> elements within the direct parent of each <p> element

Demonstrate ancestor elements by tag name


jQuery Traversal Methods

❮ Sel Onlychild Sel Multiple Classes ❯