tags:

views:

36

answers:

3

I know how to use JQuery to iterate over the children of an xml element:

$(this).children('tag_name').each(function() {

});

Is there a convenient way to simply test if an element has any children? Something like this incorrect code:

$(this).hasChildren('tag_name') //returns true or false
+2  A: 
var hasChildren = $(this).children('tag_name').length > 0;
Darin Dimitrov
A: 

$(this).find('tag_name').length > 0 to search between all the descendants $(this).children('tag_name').length > 0 for inmediate children

NicolasT
A: 

You can do -

if ( $(this).children('tag_name').size() > 0 )
{
    // do something
}
Night Shade