Since you already have a reference to table, I would use my own property .rowsto get the DOM element of the string on yours index.
Then a simple operator will work if( elm ).
var elm = tbl[0].rows[index];
if( elm ) {
row.insertBefore(elm);
}
else{
row.appendTo(tbl);
}
Less code is required and will work a little faster.
source
share