Home >>jQuery Tutorial >jQuery parent() Method

jQuery parent() Method

jQuery parent() Method

jQuery parent() method in jQuery is used to returns the direct parent element of the selected element.



Parameter Values

Parameter Description
filter It is an Optional parameter and used to specifies a selector expression to narrow down the parent search

Here is an Example of jQuery parent() Method:

.ancestors * { 
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
$("span").parent().css({"color": "red", "border": "2px solid #4abdd4"});
<div  class="ancestors">
<div style="width:500px;">div (great-grandparent)
<ul>ul (grandparent)  
<li>li (direct parent)

div (great-grandparent)
  • ul (grandparent)
  • li (direct parent) span

No Sidebar ads