tags:

views:

394

answers:

2

Hi All, Can anyone tell me how can i clone an element and then change its id. Can anyone provide me with some sample code. i want to generate a clone with a different id the code given below.

$("#Normal_Tag1_div").draggable({
            helper:'clone',
            revert: 'invalid'
            });
A: 
$("#Normal_Tag1_div").clone().attr("id", "newId")
  .draggable({ helper:'clone', revert: 'invalid' });
cletus
But it is not working.If i write the eaxct code the element stops being draggable.I have created this$("#Normal_Tag1_div").draggable({ helper:'clone', revert: 'invalid' });draggable node of which i want to create a clone so that if i want to access this id from somewhere else i can.
+1  A: 

Your question and comment do not make things very clear however I have revised my answer.

A working demo of cloning an element, renaming the id and initializing the draggable is show here.

You cant clone the element if you have already initialized the draggable as the new element when dragged will drag the old element as show here

    $("#draggable").clone()
                   .attr('id', 'newDrag')

   $('#draggable, #newDrag').draggable();
redsquare