aeq aeq - 11 days ago 5
jQuery Question

jquery check if xml element has children?

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

Answer

Use this method:

var hasChildren = $(this).children('tag_name').length > 0;