Friday, October 5, 2012

jQuery empty selector


The jQuery empty selector is used to get all the elements which do not have child elements.

:empty

In this post we shall see on how to use the jQuery empty selector to get the list of elements which do not have any child elements.

The following script gets the list of td elements which do not have any child elements.

    // Hierarchy - Empty (No Children)
    alert('Hierarchy Parent:' + $("#trName").attr('id'));
    $("td:empty").each(function() {
        alert('Hierarchy - Empty (No Children):' + $(this).attr('id'));
    });

The following script gets the list of td elements which do not have any child elements on click of the btnHierarchySelector button.

$('#btnHierarchySelector).click(function(event) {
    event.preventDefault();               
    //
    // Hierarchy - Empty (No Children)
    alert('Hierarchy Parent:' + $("#trName").attr('id'));
    $("td:empty").each(function() {
        alert('Hierarchy - Empty (No Children):' + $(this).attr('id'));

Search Flipkart Products:
Flipkart.com

No comments: