jQuery parent() get parent <div>

Description

jQuery parent() get parent <div>

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("p").parent("div").css("background-color", "yellow");
});/*w  ww  .  j  a  va2  s .  c om*/
</script>
</head>
<body>

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

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

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

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

</body>
</html>



PreviousNext

Related