Thursday, October 4, 2012

jQuery last selector


The jQuery last selector is used to get the last element in a page. 

$("input:last")

In this post we shall see on how to use the jQuery last selector to select the last element in a page.

The following script gets the the last elements in a page

    $("input:last").each(function() {
        alert('Hierarchy - Last:' + $(this).attr('id'));
    });

The following script gets the last element in a page on click of the btnHierarchySelector button.

$('#btnHierarchySelector).click(function(event) {
    event.preventDefault();               
    //
    // Hierarchy - Last
    $("input:last").each(function() {
        alert('Hierarchy - Last:' + $(this).attr('id'));

Search Flipkart Products:
Flipkart.com

No comments: