javascript - jQuery how to dynamically add a textbox with increment ID? -


i building form solely javascript , jquery. unable connect servers, unable use php script @ all.

how add more , remove textboxes "add more"and "x" (for remove) buttons increments id's can capture individual values associated each id , use them later in variable.

i have seen , tested several working examples of dynamically adding more textboxes don't have incrementing id

any suggestions helpful.

i have used data since can inbetween delete input boxes , need maintain sequential count

you can elements id #count0 , #count1 ... (make sure have null check if wish delete #count1 not there)

function addmore(){    var inps = $('#wrapper > div:last').data('count')+1 || 0;    $('#wrapper').append('<div data-count="'+inps+'"><input type=text id="count'+inps+'" class="inp"/> <a class=remove>x</a></div>');  }    $('#wrapper').on('click' , 'a.remove' ,function(){    $(this).closest('div').remove();  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id=wrapper>    </div>  <button id=add onclick="addmore()">add more</button>


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -