jQuery – Child Selector (“parent > child”)

The jQuery selector selects all direct child elements specified by “child” of elements specified by “parent”.

Source Code

<!DOCTYPE html>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
<div id="div1">
	<h2>Item 1</h2>
	<h3>Item 2</h3>
<button>Click Here</button>

jQuery("button").click(function () {
	jQuery('#div1 > h2').css("border","2px solid #1E8CBE");


Following example finds all H2 items that are children of <div id=”div1″> and create a border around them.

Item 1

Item 2


No comments yet.

Leave a Reply