1/*
2For accessing parent element details by using reference of children element.
3Just Take a look on below example:
4*/
5
6<div id="parentDiv">
7 <p>Child paragraph element</p>
8</div>
9
10$(document).ready(function(){
11 alert($("p").parent().attr("id")); // output: parentDiv
12});
13
14/*
15I hope it will help you.
16Namaste
17*/
1<!doctype html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>parent demo</title>
6 <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
7</head>
8<body>
9
10<div><p>Hello</p></div>
11 <div class="selected"><p>Hello</p></div>
12<div class="selected"><p>Hello Again</p></div>
13
14<script>
15$( "p" ).parent( ".selected" ).css( "background", "yellow" );
16</script>
17
18</body>
19</html>
20