jQuery – :nth-child() Selector

The jQuery nth-child selector selects all elements that are the nth-child of their parent.

Source Code

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

	<h4>Text 1</h4>
	<h4>Text 2</h4>
	<h4>Text 3</h4>
	<h4>Text 4</h4>
<button>Click Here</button>

jQuery("button").click(function () {
	jQuery("div h4:nth-child(2)").css({border:"3px #1E8CBE solid"});


Following example finds the second h4 in each matched div and create a border.

Text 1

Text 2

Text 3

Text 4


No comments yet.

Leave a Reply