JSFiddle - React, Tailwind, and code Playground
by Dedi Wibisono
HTML
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<div class="wrapper">
<input type="text" /><button class="add">+</button>
</div>
JavaScript
$(document).ready(function() {
var max = 5;
var wrapper = $(".wrapper");
var add = $(".add");
var x = 1;
$(add).click(function(e){
e.preventDefault();
if(x < max){
x++;
$(wrapper).prepend('<div><input type="text"/><button class="remove_field">-</button></div>');
} else{
alert("haha");
}
});
$(wrapper).on("click",".remove_field", function(e){
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});