Friday, October 5, 2012

jQuery index :gt selector


The jQuery index :gt selector is used to get all the child elements under a parent which have an index value greater that the specified value.

:gt(0)


In this post we shall see on how to use the jQuery index :gt
selector to get the list of elements which have an index value greater that the specified value.

The following script gets the child elements of the parent tr element trName which have an index greater than 0.

    alert('Hierarchy Parent:' + $("#trName").attr('id'));
    $("#trName td:gt(0)").each(function() {
        alert('Hierarchy - td with Index > 0:' + $(this).attr('id'));
    });

The following script gets the child elements of the parent tr element trName which have an index greater than 0 on click of the btnHierarchySelector button.

$('#btnHierarchySelector).click(function(event) {
    event.preventDefault();               
    //
    // Hierarchy - Index
    alert('Hierarchy Parent:' + $("#trName").attr('id'));
    $("#trName td:gt(0)").each(function() {
        alert('Hierarchy - td with Index > 0:' + $(this).attr('id'));

Search Flipkart Products:
Flipkart.com

No comments: