English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery parent() Method

jQuery Traversal Methods

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

The parent() method moves one level on the DOM tree. To traverse the root element of the document, please useparent()Method.

Syntax:

$ (selector).parent(filter)

Example

Return the direct parent of each paragraph:

$ ("p").click(function() {
  $ (this).parent();
});
Test see if‹/›

Return the direct parent of each paragraph with the 'selected' class:

$ (document).ready(function() {
  $("p").parent(".selected").css("background", "coral");
});
Test see if‹/›

The parent() method moves one level on the DOM tree. The following example returns the direct parent of the SPAN:

div (great-grandparent)
div (grandparent)

p (direct parent)                 span

Run Code

Parameter Values

ParametersDescription
filterSpecify a selector expression to match elements (optional)

jQuery Traversal Methods