iyal iyal - 1 year ago 46
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=""/>

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');


How to solve this, thanks in advance.

Answer Source

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;