I have a form which allows user to add elements(which might be a field set or a text box) dynamically. I'm able to assign a new ID to the elements when added but I'm not able to make it in a sequence as the user can add elements in between as well. So for example, there is an Id named XXX1 and the user adds a new element after it which is xxx2. Now if the user adds a new element again after XXX1, it comes up as XXX3. So the order of the elements is XXX1, XXX3, XXX2. I'm not able to control the names when it is being added. So I'm trying to re-assign the names after add. I'm trying to get all elements in an array and change the ID as follows \[code\]document.getElementById('xxx3').setAttribute('id', 'xxx2');\[/code\]But this doesn't work as ID XXX2 already exists for another element. Please help me with a solution for this.