jquery - Adding and removing input fields -


i have requirement add 4 input fields when user clicking addagent button. allow user remove 1 of those. if user adds 4 input fields, want disable add button. if user removes 1 of 4 input fields, enable add button 1 more add or 2 more add, depending on how many inputs user removed or added. max four. jquery, or sample can get? thanks!

here working jsfiddle [demo]

 <div id="add">add</div>     <div id="container"></div>  $('#add').bind('click', function() {     if($('#container').find('input').length < 4) {         $('#container').append('<div><input type="text"><span class="remove">remove</span></div>');     } })  $('body').on('click', '.remove', function() {     if($('#container').find('input').length > 0) {         $(this).parent().remove();     } }) 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -