jQuery – :first Selector

The jQuery first selector selects the first matched element. The :first pseudo-class is equivalent to :eq(0). It could also be written as :lt(1). Also, the :first matches only a single element.

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>
<button>Click Here</button>

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


Following example finds the first H4 element and create a border around them.

Text 1

Text 2

Text 3


No comments yet.

Leave a Reply