Search code examples
javascriptjqueryvml

jquery.clone() attrs of elements


I create vml element v:shape, add styles and attributes, and then append it.

var shape = document.createElement("v:shape");
//some attrs
shape.setAttribute("coordorigin", "0 0");
shape.setAttribute("coordsize", w + " " + h);
shape.setAttribute("stroked", "false");
//...
//some styles
shape.style.position = "absolute";
shape.style.top = 0 + "px";
shape.style.left = 0 + "px";
shape.style.width = w + "px";
shape.style.height = h + "px";
//...
$(element).append(shape);

And I want to append the same shape to another place

var shape2 = $(shape).clone(true);

but it clones only styles

alert(shape2.css("position")); // absolute
alert(shape2.attr("coordsize")); // undefined

What sholuld I do? Help me please)
[EDIT] Thanks for your answers) Its weird for me... I noticed that it works when I append it to the element if var element = document.createElement("p"); but I get my element by $(selector).each(function(index, element) { Even when I append it to the body it doesn't work(


Solution

  • It works for me if I dummy in the missing values: http://jsfiddle.net/JAAulde/hKCHX/1/ (Tried in Safari, Chrome, and Firefox)