jay jay - 11 months ago 40
jQuery Question

How to increment a id when appending elements using jquery?

$("div2").append("<div class=fieldBlock><label >Parameter Name: </label><select type=text id=name2 name=name2 ><option></option></select> </br>");

I have created a button that appends a parameter drop down select when the button is clicked. I want to give each appended select a different id. For example, when button is pressed for first time, that select will have id name2, then if button is pressed again, the new append select will have id name3, and so forth. Any way of doing this?


This shoud work for you.

Fiddle of it working.

var count = 0;
   $(".div2").append("<div class='fieldBlock'><label >Parameter Name: </label><select id='name" + count + "'  name='name" + count + "' ><option></option></select></div> </br>");