0
我想讓我的代碼使用函數刪除一個新的div。刪除創建的Div
JavaScript可以添加一個新的div沒有任何問題。但刪除按鈕不響應。
如何讓我的JavaScript刪除div。
腳本:
\t <script async> // hidden answer for adding new answers jacascript code
\t \t \t function clonebutton1 (counter){
\t \t \t \t counter = counter +1;
\t \t \t \t var div = document.createElement('div');
\t \t \t \t div.className = 'container-fluid form-group col-lg-6';
\t \t \t \t div.innerHTML ='<label>Answer:\
\t \t \t <span id="ansNo">'+counter+'</span>\
\t \t \t </label> \
\t \t \t <input class="form-control" id="AnswerClone" name="quizAnswerNew[]" placeholder="Please Enter An Answer......" type="text" value="">\
\t \t \t <div class="form-group">\
\t \t \t \t <label for="select1">Pick a Score For The Answer:</label> \
\t \t \t \t <select class="score-choice" id="selectClone" name="selectNew">\
\t \t \t \t <option selected value="0">0</option><option value="5">5</option><option>10</option><option>15</option><option>20</option>\
\t \t \t \t </select>\
\t \t \t </div>\
\t \t \t <div style="margin-bottom:20px;">\
\t \t \t \t <label class="btn-bs-file btn btn-sm btn-primary">Add Picture <input name="answerFileNew" type="file"></label>\
\t \t \t </div><input class="btn btn-primary removeAnswer" id="removeAnswer" type="button" value="Remove Answer">\
\t \t </div>';
\t
\t \t \t document.getElementById('AnswerSectionNew').appendChild(div);
\t \t \t \t \t div.on("click", function() {// this function removes the parent of the removeAnswer button that is clicked
\t \t \t \t \t \t \t \t \t $(this).parent().remove();
\t \t \t \t \t });
\t \t \t document.getElementById('addAnotherAnswer').setAttribute("onClick","clonebutton1("+counter+")");
\t };
\t \t \t
\t \t \t
\t
\t </script>
感謝