Get the div parent - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:parent

Description

Get the div parent

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").parent("div").css("color", "red");
});//  ww w  .ja  v a 2  s  .c  o  m
</script>
</head>
<body>

<p>This is a p element in body.</p>

<div style="border:1px solid;">
  <p>This is a p element (child of div).</p>
  <span>This is a span element (child of div).</span>
  <p>This is also a p element (child of div).</p>
</div><br>

<div style="border:1px solid;">
  <p>This is a p element (child of div).</p>
  <span>This is a span element (child of div).</span>
  <p>This is also a p element (child of div).</p>
</div>

<p>This is also a p element in body.</p>

</body>
</html>

Related Tutorials