Reputation: 11
Actually I want to create an unique id for every DOM element which is cloning when the DOM element is dropped in a container and show it in a text area. That text area will show every DOM element's unique id in a list which is dropped in the container. Answer should be in jQuery.
Can any one there to help me?
Upvotes: 0
Views: 445
Reputation: 1515
for(var i=0; i<=10;i++)
$('#clonedSource').clone().attr('id', 'newElementId'+i).appendTo('#container');
Upvotes: 0
Reputation: 1074138
Just spin through the elements (using jQuery, or just a boring old recursive descent function using the DOM) and set their id
property to something unique.
To set the id
of an element using the DOM:
element_reference.id = newId;
With jQuery (1.6 and higher):
jquery_instance.prop("id", newId);
Upvotes: 1