I have the following Javascript:
$("div.duplicate-fields:last-child").clone().find('input').each(function() { this.name = this.name.replace(/\[(\d+)\]/,function(str,p1){return '[' + (parseInt(p1,10)+1) + ']'}); this.value = ""; this.checked = false; }).removeClass("active").end().appendTo("#duplicate-section");
Inside the .click() function. It works great. However, I have the following HTML in the cloned area:
<div class="btn-group" data-toggle="buttons"><label class="btn btn-default button-array "><input type="checkbox" name="select-sessions[3][1]" value="">Session 1</label> <label class="btn btn-default button-array "><input type="checkbox" name="select-sessions[3][2]" value="">Session 2</label> <label class="btn btn-default button-array "><input type="checkbox" name="select-sessions[3][3]" value="">Session 3</label> <label class="btn btn-default button-array "><input type="checkbox" name="select-sessions[3][4]" value="">Session 4</label> <label class="btn btn-default button-array active"><input type="checkbox" name="select-sessions[3][5]" checked="" value="">Session 5</label> </div>
Now, in the jQuery above, I have this.checked=false; which blocks any cloned flag. But unfortunately, label.button-array still has an active class, which means that it still looks like it has been checked.
So, I modified the jQuery function as follows:
$("div.duplicate-fields:last-child").clone().find('input').each(function() { this.name = this.name.replace(/\[(\d+)\]/,function(str,p1){return '[' + (parseInt(p1,10)+1) + ']'}); this.value = ""; this.checked = false; }).find("label.button-array.active").each(function() { $(this).removeClass("active"); }).end().appendTo("#duplicate-section");
Note that the new find() function is added to the first. However, it seems that it completely removes all the HTML from the clone, and in the end I get a few input fields and something about it. I canβt understand why.
In this image you can see the first cloned area, and then after clicking the button (with the find() function added, as shown above):

Help me stack overflow, you are my only hope.