please see jsfiddle.
I have a button that append a new row to the table. then I want to update the id for the newly added row so each row is unique. however the squence is wrong.
for example. I expect getting
You don't need to use
html() for cloning - jquery comes with a clone feature that is much more efficient.
Also, you always want to make as many changes to a DOM node as you can before inserting it into the DOM. In this case, you want to set the ID of the new select box before you attach the new row. The reason is because once a DOM node has been inserted (eg, you can see it in the page), every change causes it to be rerendered - which is just inefficient.
Take a look at this updated fiddle: