jQuery – :parent Selector

The jQuery parent selector select all elements that are the parent of another element, including text nodes. This is the inverse of :empty.

Source Code

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<div>
	<h3>Text 1</h3>
</div>
<button>Click Here</button>

  
<script>
jQuery("button").click(function () {
	jQuery("h3:parent").css({border:"3px #1E8CBE solid"});
});
</script>
</body>
</html>

Demo

Following example finds all <h3> with children, including text and create a border.

Text 1

,

No comments yet.

Leave a Reply