开发者

Adding Table rows using jQuery in Firefox

I am trying to add rows to my repeater using jQuery using below script.It is working perfect in IE, but not in Firefox, Chrome and Safari.

looks like issue with using of outerHTML. Can someone help me?

function开发者_开发技巧 AddRowToTable(table) {
    var newRow1 = $(table.rows[table.rows.length - 2].outerHTML);
    var myRow = $(table.rows[table.rows.length - 2]);
    $(myRow).after(newRow1);
}


outerHTML is a proprietary standard, unsupported by browsers other than IE. It's a bad idea anyway -- you should almost always just use the DOM nodes and clone them where necessary. Fortunately, jQuery makes this very easy for you.

function AddRowToTable(table) {
    var $table = $(table);
    var $oldRow = $table.find('tr').eq(-2); // get the second last row
    var $newRow = $oldRow.clone(true); // clone the node
    $oldRow.after($newRow); // insert the new row after the old row
}

See:

  • eq
  • clone
  • after


Possible duplicate of Add table row in jQuery

The solution was

$('#myTable tr:last').after('<tr>...</tr><tr>...</tr>');

You can probably modify that to being useful in your case...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜