---
title: "parent() method usage in jQuery"  
description: "parent() method usage in jQuery"  
author: "Ethan Karla"  
published: 2021-07-28  
updated: 2023-11-26  
canonical: https://www.mindstick.com/forum/156649/parent-method-usage-in-jquery  
category: "jquery"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# parent() method usage in jQuery

What is the [parent](https://www.mindstick.com/blog/154/how-to-find-parent-of-control-in-wpf)() [method](https://www.mindstick.com/forum/166/webservice-method) [usage](https://www.mindstick.com/forum/155707/what-is-the-usage-of-asp-dot-net-configuration-file) in jQuery?

## Replies

### Reply by Aryan Kumar

In jQuery, the **parent()** method is used to traverse up the DOM hierarchy and select the parent element of the matched set of elements. It returns a set containing the unique ancestors of each element in the original set, optionally filtered by a selector.

### Syntax:

```plaintext
$(selector).parent([filter])
```

- **selector (optional):** A string containing a selector expression to filter the parent elements.
- **filter (optional):** A string containing a selector expression to filter the results.

### Example:

```plaintext
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>jQuery parent() Method Example</title>
  <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<body>

<div class="parent">
  <p>Parent Element</p>
  <div class="child">
    <p>Child Element</p>
  </div>
</div>

<script>
  $(document).ready(function() {
    // Select the parent of the element with class 'child'
    var parentElement = $('.child').parent();

    // Output the text content of the parent element
    console.log("Parent Element Text: " + parentElement.text());
  });
</script>

</body>
</html>
```

In this example:

1. The **parent()** method is used to select the parent element of the element with the class 'child'.
2. The text content of the parent element is then logged to the console.

Keep in mind that **parent()** only selects the immediate parent. If you want to traverse up multiple levels, you can chain multiple **parent()** calls or use the **parents()** method with an optional filter.


---

Original Source: https://www.mindstick.com/forum/156649/parent-method-usage-in-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
