I'm trying to add and remove textboxes dynamically. Adding of textbox is working fine, but removing the textbox is not working. I've defined the onclick method on button element itself. Am I missing anything? There should be a simple mistake.
Here is my code
var container = document.getElementById('divArea');
function RemoveTextBox(div) {
document.getElementById("divArea").removeChild(div.parentNode);
}
function addTextBox(value){
return '<input name="newTextBox" type="text" value = "' + value + '" />' +
'<input type="button" value="Remove" class="removeTxtBox" onclick = "RemoveTextBox(this)" />'
}
document.getElementById('btnAdd').onclick = function() {
var res = document.getElementById('val').value;
var div = document.createElement('DIV');
div.innerHTML = addTextBox(res);
container.appendChild(div);
}
My JS Fiddle https://jsfiddle.net/2ddaw4zf/1/