I want to be able to clone a checkbox when it is clicked, and the cloned checkbox will be unchecked. When the cloned checkbox is checked, it will clone itself and the process repeats.
<section class="misc">
<div class="row">
<label class="label"><input type="checkbox" class="others"> Others:</label>
</div>
<div class="row">
<div class="col-md-6"><input type="text" class="form-control" placeholder="Others"/></div>
</div>
</section>
<div class="sth"></div>
<!-- Clone the "Others" checkbox with textbox when the original checkbox is checked. I want each subsequent clone to be unchecked, then clone itself.. -->
<script>
$(".others").change(function(){
if($(this).is(':checked'))
{
var clone=$(this).parents('section').clone();
$('.sth').html(clone);
}
});</script>
Right now, I'm only able to clone the original and the cloned checkbox is checked instead of unchecked.
Jsfiddle: http://jsfiddle.net/cLkvxydh/
Aucun commentaire:
Enregistrer un commentaire