jQuery – :even Selector

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

Source Code

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

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

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

Demo

Following example finds even H4 elements, matching the first, third and so on (index 0, 2, 4 etc.) and create a border around them.

Text 1

Text 2

Text 3

,

No comments yet.

Leave a Reply