jQuery – :last Selector

The jQuery last selector selects the last matched element.

Source Code

<!DOCTYPE html>
<!DOCTYPE html>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
<div id="div1">
<h4>Text 1</h4>
<h4>Text 2</h4>
<h4>Text 3</h4>
<button>Click Here</button>
jQuery("button").click(function () {
	jQuery("#div1 h4:last").css({border:"3px #1E8CBE solid"});


Following example finds the last H4 element (inside <div id=”div1″>) and create a border around them.

Text 1

Text 2

Text 3


No comments yet.

Leave a Reply