$(parentQuestion.children('.choice_class:last'));
<div class='parentquestion'> .....
<div class="choice_class">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12"><span class="choice-no">Option 1</span><span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" required="required" class="form-control col-md-7 col-xs-12">
</div>
<a href="javascript: void(0);" onclick="addOption(this)" class="btn btn-danger"><span class="glyphicon glyphicon-plus"></span>Add Choice</a>
</div>
</div>
inside addOption関数この変数を使用して、親オブジェクトを見つけて最後の.choice_classの下に別のオプションを追加しました。Jquery子供の子供elemnt
2番目のオプションを追加すると、オプション1をオプション2に変更する必要があります。
完全な機能が
function addOption(that) {
$(that).parent().parent().after($('.choice_class_sample .choice_class').clone());
var parentQuestion = $(that).parent().parent().parent();
var lastChoice = parentQuestion.children('.choice_class:last');
$(parentQuestion.children('.choice_class:last-child .choice-no')).html(parentQuestion.children('.choice_class').length);
$(that).remove();
}
あるしかし、私は子供を選択した後、さらにより選択することはできませんよ。
アドバイスをいただきありがとうございます。それは清潔できれいに見えます。私は複数の質問があることを言及する必要があります。すべての質問には独自のオプションがあります。 – Mahesh
私のコーディングでは、find()を使用して問題を解決しました。しかし、私はあなたがアドバイスしたとおりにそれらを変更しています。ありがとう – Mahesh