What I want to reach, is to generate dynamically text boxes with jQuery, so, the jQuery code:
var num = $('.question-container-1').length;
var newNum = new Number(num + 1);
var newElem = $('#question-container-' + num).clone().attr('id', 'question-container-' + newNum);
newElem.children('input[type=text]').val('');
$('#question-container-' + num).after(newElem);
and the html code:
<fieldset id="question-container-1" class="question-container-1">
<div class="control-group">
<label class="control-label" for="input01">Întrebare</label>
<div class="controls">
<input type="text" name="question" id="question-box" value=""/>
</div>
</div>
</fieldset>
<fieldset>
<div class="control-group">
<div class="controls">
<a href="#" id="add-question-1" class="add-question-1">Adaugă întrebare</a>
<a href="#" id="delete-question-1" class="delete-question-1" style="margin-left: 20px;">Șterge întrebare</a>
</div>
</div>
</fieldset>
After all, everything works perfectly, except for one thing, they are clones from the last textfield, but I don’t want to copy the value of it as well, how you can see I tried with children function to find textfield, but it does not erase the value
.children()works only one descendant level down. You want.find()instead, which goes all the way down to the last, farthest descendant. 😀