tags:

views:

25

answers:

2

if in html table have 5 row, 1 and 2 are safe, 3,4,5 must be saved as html structure to a variable. like this

var after2ndContent= '<tr><td>3</td></tr><tr><td>4</td></tr><tr><td>5</td></tr>' 
+1  A: 

As jQuery does not have an outerHTML function, it's a bit tricky:

$('<table>').append($('tr:gt(1)').clone()).remove().html();

That is:

  • Create a dummy table element
  • Append the rows after the second row (gt() is zero-indexed)
  • Get the contents of this table (including the <tr> tags) and remove the element

If you simply used $('tr:gr(1)').html(), you'd probably just get the contents of the first <tr>.

Tatu Ulmanen
sorry, but i have some problem. var after2ndContent=$('#dictTable').append($('tr:gt(1)').clone()).remove().html();alert(after2ndContent) it shows full html content of page
loviji
+1  A: 

Since this is a continuation of your previous post, you can use this

var elemRemoved = $("#tbl1 tr:gt(1)").detach();
var removedContents = $("<div />").append(elemRem).remove().html();
alert ( removedContents );
rahul
thanks, it works great. is possible to get live html content?because in <td> tags has <input type="text" />. alert ( removedContents ); return "<tr bgcolor="#33ff66"><td><input id="txt91" type="text"></td><input id="txt92" type="text"></tr>". without input values. it will be very nice, if i can get with input values...
loviji