Thursday, October 4, 2012

jQuery first selector


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

$("input:first")

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

The following script gets the the first elements in a page

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

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

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

Search Flipkart Products:
Flipkart.com

No comments: