Well Wisher
Well Wisher

Reputation: 1875

Cloning is not working

var j=0;  
var cloneObj='<div class="ui-widget-content"><div class="form_container-'+j+'">
<div class="placeholder">Add your form fields here</div><div style="clear: both;" >   
</div></div> </div>';

and cloning as

  $('.button_class').click(function(j){
   $(cloneObj).clone(false).appendTo('body');
   j++;
   console.log(j);
 });

is not working any solution.?

Upvotes: 0

Views: 77

Answers (2)

Anton
Anton

Reputation: 32591

$('.button_class').click(function () {
    var cloneObj = '<div class="ui-widget-content"><div class="form_container-' + j + '"><div class="placeholder">Add your form fields here</div><div style="clear: both;" ></div></div> </div>';
    $(cloneObj).appendTo('body');
    j++;
    console.log(j);
});

You need to put cloneObj inside the click button to increment j and remove j from function(j) and you dont need to clone the object just append it

DEMO

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388436

you don't have to use clone here

 $('.button_class').click(function(j){
   $(cloneObj).appendTo('body');
   j++;
   console.log(j);
 });

Upvotes: 1

Related Questions