Recursive function

Recursive function

Hi there,
I have a table in which each row has its ID and PARENT-ID who points to the parent row(record). I am trying to create a recursive function to remove a parent row and all its children rows. of course child row might be a parent of other rows.

Following code is not final and might be buggy.
function removeBranch(bID) {
            var k = $("[pID='" + bID + "'][isparent]");
            if (k.length > 0) {
                $.each(k, function (i,o) {
                    removeBranch(o.id);
                }); 
            } else {
                $("[pID='" + bID + "']").remove();
                //removeBranch(bID);
                //return;
            }
        }




The issue is when I call the function from within itself I get the following error -

SCRIPT28: Out of stack space

Any idea what might be the problem ?