-->

jQuery :last-child Selector

By: Bipin C Mathew 4 months, 3 weeks ago

The :last-child selector lets you select every element that is the last child of its parent, while the:last selector selects only the last one from the element set.

Syntax   $(":last-child")

Example

<!doctype html>
	<html lang="en">
	<head>
	  <meta charset="utf-8">
	  <title>first-child demo</title>
	 <style>
	  span.solast {
	    text-decoration: line-through;
	  }
	  </style>
	  <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
	</head>
	<body>
	 
	<div>
	  <span>Sibin,</span>
	  <span>Jobby,</span>
	  <span>Bobby</span>
	</div>
	<div>
	  <span>Kevin,</span>
	  <span>Shorn,</span>
	  <span>Ginu</span>
	</div>
	 
	<script>
	$( "div span:last-child" )
	  .css({ color:"green", fontSize:"80%" })
	  .hover(function() {
	    $( this ).addClass( "solast" );
	  }, function() {
	    $( this ).removeClass( "solast" );
	  });
	</script>
	 
	</body>
	</html>

Comments

Let us talk!

We take the vision which comes from dreams and apply the magic of science and mathematics, adding the heritage of our profession and our knowledge to create a design.