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:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
17 May, 2023
Like Article
Save Article