jQuery – :odd Selector

The jQuery odd selector selects odd elements within the matched set. : odd selector use 0-based indexing.

Source Code

<!DOCTYPE html>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
<div class="div1">
<h4>Text 1</h4>
<h4>Text 2</h4>
<h4>Text 3</h4>
<button>Click Here</button>

jQuery("button").click(function () {
	jQuery("div.div1 > h4:odd").css({border:"3px #1E8CBE solid"});


Following example finds odd h4 elements (in div having class=”div1″), matching the second, fourth and so on (index 1, 3, 5 etc.).

Text 1

Text 2

Text 3


No comments yet.

Leave a Reply