Add table row using jQuery and JavaScript

I noticed that there are a lot of developers who need to dynamically add a new table row to the bottom of their tables. I wrote a little javascript function that takes your jQuery selection of tables and dynamically adds a table row at the bottom of them.

jQuery add table row function definition:

/*
    Add a new table row to the bottom of the table
*/


function addTableRow(jQtable){
    jQtable
.each(function(){
       
var $table = $(this);
       
// Number of td's in the last table row
       
var n = $('tr:last td', this).length;
       
var tds = '<tr>';
       
for(var i = 0; i < n; i++){
            tds
+= '<td>&nbsp;</td>';
       
}
        tds
+= '</tr>';
       
if($('tbody', this).length > 0){
            $
('tbody', this).append(tds);
       
}else {
            $
(this).append(tds);
       
}
   
});
}

jQuery add table row function usage example:

addTableRow($('#myTable'));
addTableRow
($('.myTables'));