JSFiddle - React, Tailwind, and code Playground
HTML
<form>Quiz name:
<input type="text" name="firstname" />
<br/>Question name:
<input type="text" name="lastname" />
</form>Choice
<input type="text" name="textBox0">
<input type="button" value="add" onclick="addInput()" />
<span id="responce"></span>
JavaScript
// From: http://stackoverflow.com/questions/3387427/javascript-remove-element-by-id
Element.prototype.remove = function () {
this.parentElement.removeChild(this);
};
NodeList.prototype.remove = HTMLCollection.prototype.remove = function () {
for (var i = 0, len = this.length; i < len; i++) {
if (this[i] && this[i].parentElement) {
this[i].parentElement.removeChild(this[i]);
}
}
};
var countBox = 1;
var boxName = 0;
function addInput() {
var boxName = "textBox" + countBox;
var divName = "Div_" + countBox;
document.getElementById('responce').innerHTML += '<br/><div id="' + divName + '"> Choice<input type="text" id="' + boxName + '" /><input type="button" value="add" onclick="addInput()"/><input type="button" value="delete" onclick="deleteInput(' + divName + ')"/></div>';
countBox += 1;
}
function deleteInput(param_divName) {
document.getElementById('responce').innerHTML += 'choice';
document.getElementById(param_divName.id).remove();
}