$(selector).parent(filter)
<!DOCTYPE html>
<html>
<head>
<style>
.main *{
font-size: 20px;
border: 2px solid black;
color: black;
padding: 10px;
margin: 17px;
}
</style>
<script src = "/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function fun(){
$(document).ready(function(){
$("h2").parent().css({ "font-size": "30px", "color": "blue", "border": "6px dashed blue"});
});
}
</script>
</head>
<body class = "main">
<div> div
<ul> ul
<h2> Heading h2
<p> Paragraph element </p>
</h2>
</ul>
</div>
<button onclick = "fun()"> click me </button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.main *{
font-size: 20px;
border: 2px solid black;
color: black;
padding: 5px;
margin: 10px;
}
</style>
<script src = "/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function fun() {
$(document).ready(function(){
$("p").parent(":first").css({"color": "blue", "border": "3px dashed blue"});
});
}
</script>
</head>
<body class = "main"> body
<div> div1
<div> div2
<h2> h2
<p> Paragraph element </p>
</h2>
<h2> h2
<p> Paragraph element </p>
</h2>
</div>
</div>
<button onclick = "fun()"> click me </button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.main *{
font-size: 20px;
border: 2px solid black;
color: black;
padding: 5px;
margin: 10px;
}
</style>
<script src = "/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function fun() {
$(document).ready(function(){
$("p").parent("h2").css({"color": "blue", "border": "5px dashed blue"});
});
}
</script>
</head>
<body class = "main"> body
<div> div1
<div> div2
<p> Paragraph element </p>
</div>
<h2> h2
<p> Paragraph element </p>
</h2>
<ul> ul
<p> Paragraph element </p>
</ul>
</div>
<button onclick = "fun()"> click me </button>
</body>
</html>