Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is Jquery last() method ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 396
    Comment on it

    Hello Readers,

    last() is the jquery method which is used to select or returns the last element of the selected elements or the matched elements in jquery.

    Syntax :

    $(selector).last()
    

    In the above syntax there is no parameter inside last() method.

    Code Example :

    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("div p").last().css("background-color", "yellow");
    });
    </script>
    </head>
    <body>
    
    <h1>Welcome to My Homepage</h1>
    
    <div style="border:1px solid black">
      <p>This is a paragraph in a div.</p>
      <p>This is a paragraph in a div.</p>
    </div><br>
    
    <div style="border:1px solid black">
      <p>This is a paragraph in another div.</p>
      <p>This is a paragraph in another div.</p>
    </div>
    
    <p>This is also a paragraph.</p>
    
    </body>
    </html>
    

    In the above code select the last paragraph p element inside the last div element in jquery.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: