selector - insertBefore()
how can you use insertBefore() when you don't have the id, class or anything for the table but only the object?
var tbl_elm = $('the table');
$('<tr><td>txt</td></tr>').insertBefore(tbl_elm.eq(0));
somehow I need to tell the eq() that the index ha开发者_如何学Cs to be found in a 'TR' tag
Try this:
var tbl_elm = $("TABLE");
$('<tr><td>txt</td></tr>').insertBefore($("TR", tbl_elm).eq(0))
However, if the elements you are adding to the table will always be placed before the first row, the below code is better practice:
var tbl_elm = $("TABLE");
$('<tr><td>txt</td></tr>').prependTo(tbl_elm)
精彩评论