issue with insertBefore()
<p>I got a small object which has to append new rows to a table.. It works fine in most cases, but if there is a table inside some of the rows (in the "root" table) the object doesn't append to the proper table!?</p>

<p>I have been doing a bit of debugging and found the line where it all goes wrong.. If DEBUG is set and the line with insertBefore() is omitted the object appends to the proper table</p>

<pre><code>var List = new function(){
    this.append_row = function(row, tbl, index){
        if(DEBUG){
            index = -1;
        }

        if(index == 0){
            row.prependTo(tbl);
        }
        else if(index &gt; 0){
            var elm = $('tr', tbl);
            if(elm.length &gt; index){
                row.insertBefore(elm.eq(index)); // the issue is in this line
            }
            else{
                row.appendTo(tbl);
            }
        }
        else{
            row.appendTo(tbl);
        }
    };
}
</code></pre>
