jQuery - end( ) Method


Advertisements


Description

The end( ) method reverts the most recent destructive operation, changing the set of matched elements to its previous state right before the destructive operation.

Syntax

Here is the simple syntax to use this method −

operations.end( )

Parameters

Here is the description of all the parameters used by this method −

  • NA

Example

Following is a simple example a simple showing the usage of this method. This selects all paragraphs, finds span elements inside these, and reverts the selection back to the paragraphs.

Live Demo
<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script>
         $(document).ready(function(){
            $("p").find("span").end().css("border", "2px red solid");
         });
      </script>
		
      <style>
         p{ 
            margin:10px; 
            padding:10px; 
         }
      </style>
   </head>
	
   <body>
      <p><span>Hello</span>, how are you?</p>
   </body>
</html>

This will produce following result −


jquery-traversing.htm

Advertisements