Add / Remove Input Feld Dynamically
Add / Remove Input Feld Dynamically
HTML
<div id="Dynamic">
<div>
<input type="text" />
</div>
</div>
<a href="#" id="AddInpElem">Add Another Input Box</a>
JavaScript
var MaxInputs = 5;
var Dynamic = $('#Dynamic');
var i = $('#Dynamic div').size() + 1;
$('#AddInpElem').click( function () {
if (i <= MaxInputs) {
$('<div><button autofocus>I should be autofocused</button><a href="#" class="RemInpElem">Remove</a></div>').appendTo(Dynamic);
i++;
}
return false;
});
$("body").on("click",".RemInpElem", function(){
if (i > 2) {
$(this).parent('div').remove();
i--;
}
return false;
})