---
title: "Select any parent element of any tag via jQuery"  
description: "Select any parent element of any tag via jQuery"  
author: "Ethan Karla"  
published: 2021-07-29  
updated: 2023-06-12  
canonical: https://www.mindstick.com/forum/156679/select-any-parent-element-of-any-tag-via-jquery  
category: "jquery"  
tags: ["jquery", "html"]  
reading_time: 2 minutes  

---

# Select any parent element of any tag via jQuery

How to [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) any [parent](https://www.mindstick.com/blog/154/how-to-find-parent-of-control-in-wpf) element of any tag via jQuery?

\

## Replies

### Reply by Aryan Kumar

Sure, here is how to select any parent element of any tag via jQuery:

JavaScript

```plaintext
// Select all elements with the "my-element" class
var elements = $(".my-element");

// Get the parent of each element
var parents = elements.parent();

// Do something with the parents
parents.css("color", "red");
```

This code will select all elements with the `my-element` class and then get the parent of each element. The `parents` variable will now contain a jQuery object that represents all of the parent elements. You can then use this jQuery object to do something with the parents, such as change their color to red.

Here is another example:

JavaScript

```plaintext
// Select all paragraphs
var paragraphs = $("p");

// Get the parent of each paragraph
var parents = paragraphs.parent();

// Do something with the parents
parents.css("font-size", "20px");
```

This code will select all paragraphs and then get the parent of each paragraph. The `parents` variable will now contain a jQuery object that represents all of the parent elements. You can then use this jQuery object to do something with the parents, such as change their font size to 20px.


---

Original Source: https://www.mindstick.com/forum/156679/select-any-parent-element-of-any-tag-via-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
