iyal iyal - 7 months ago 9
HTML Question

Appending outer html with input number in it

I am trying to get tbody html to append to another table. And this table have an input number in it.

<tbody class="onetable tbody">
.....
.....
<input type="number" value=""/>
.....
<tbody>


Before appending this tbody, I change the value of the input of number, forexample 3.

However, after placing the tbody to another table, the value of input reset to 1, not 3.

var wholeTbody = $("#onetable.tbody").prop('outerHTML');

$("#anotherTable").append(wholeTbody);


How to solve this, thanks in advance.

Answer

You can't get the values in the outerHTML unless you set it manually as value attribute.

var wholeTbody = $("#onetable.tbody").find("input[type='text']").attr("value",function(){
  return this.value;
}).end().prop('outerHTML');

$("#anotherTable").append(wholeTbody);
Comments