Open In App

How to select direct parent element of an element in jQuery ?

Last Updated : 17 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will select the direct parent element of an element using jQuery. To select the direct parent element, the parent() method is used. This method finds the parent element related to the selected element. This parent() method traverses a single level up the selected element and returns that element.

Syntax:

$(selector).parent()

Example:  Here is the implementation of the above method.

HTML




<!DOCTYpe html>
<html>
<head>
    <title>
        How to select direct parent element
        of an element in jQuery?
    </title>
 
    <script src=
    </script>
 
    <script>
        $(document).ready(function () {
            $("li").parent().css({
                color: "white",
                background: "green"
            });
        });
    </script>
</head>
 
<body>
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
 
    <h3>
        How to select direct parent element
        of an element in jQuery?
    </h3>
 
    <p>GeeksforGeeks Subjects List-</p>
 
    <ul>
        <li>HTML</li>
        <li>CSS</li>
        <li>JavaScript</li>
        <li>PHP</li>
    </ul>
</body>
</html>


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads