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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -