On the page there are calculations, displayed in the form, namely in the text fields. Then I need to get the whole form with the results. The problem is that html() does not take the value text fields after the calculation.

I tried to do this

 var res = 5 + 15; $("#res").val(res) $("#btn1").click(function() { var code = $("#wrapp").html(); $("#wrapp2").html(code) }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="wrapp"> <input type="text" id="res" /> <button id="btn1">Click</button> </div> <div id="wrapp2"></div> 

It does not work. The calculated value values ​​are not transferred to the copied form.

It is necessary that when you click the button (example above) a form appears with filled values.

  • If you made the simplest example on jsfiddle or any other resource, it would be great and much clearer =) - Skywave
  • what does not work? how not to work? what behavior was expected? - Grundy
  • Updated, now there is a Piermer - zkolya
  • Why do you need to duplicate the form? - Grundy
  • The question is not this, but how to take everything at one stroke)) - zkolya

1 answer 1

If I understand the question correctly then something

 (function($) { newEl = function() { console.log('test'); var sample = $(".sample:first-child").clone(); sample.on("click", newEl); sample.appendTo(".inner"); } $('.sample').on("click", newEl); })(jQuery); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="inner"> <input class="sample" type="text" /> </div>