Search code examples
jquerycheckboxappendlive

append inside append (dynamically appended) by jQuery


problem with appending div

I would like to append element inside an appended element

I appended a button and on that button I want to append the form(in a new div)

I am very thankful for any help

http://codepen.io/hesham-farag/pen/RKZaoe

  var addcheck = $(".add-checkbox"),
      // button for form        
      addcheck_box = $(".add-box-checkbox"),
      // add form       
      box_checkboxx = "<form class=\"check-control\"><div class=\"checkbox\"><input class=\"form-control\" type=\"type\" name=\"test"+clicked+"\" value=\"test\" /></div><input type=\"checkbox\"  name=\"test"+clicked+"\" value=\"test\" /><input class=\"form-control\" type=\"type\" name=\"test"+clicked+"\" value=\"test\" /><a href=\"\" class=\"add-checkbox\">add new</a></div>",
      // add add checkbox & input  
      checkboxx = "<div class=\"checkbox\"><input type=\"checkbox\"  name=\"test"+clicked+"\" value=\"test\" /><input class=\"form-control\" type=\"type\" name=\"test"+clicked+"\" value=\"test\" /></div></form>",
      // valu zero       
      clicked = 0;

    addcheck_box.on("click",function(){ 
      $(".wrap-surve-input").append( box_checkboxx);
    });



    addcheck.on("click",function(){ 
      clicked++;
      $("form").append(checkboxx);
    });

Solution

  • I check your code and i have fix some bit in your code to fit what u need as i try to get what u need exactly please check this link i made new fork

    http://codepen.io/Ahmed-Elemam/pen/MJvqmx

    $(document).on("click",".add-box-checkbox",function(){ 
      $(".wrap-surve-input").append( box_checkboxx);
    });
    
    
    $(document).on("click",".add-checkbox",function(){
    //addcheck.on("click",function(){ 
      clicked++;
      $("form").append(checkboxx);
    });