1
I have an SVG element created from a clone. I wanted to insert this clone into a new div. I used this code.
function clone(){
var newrect = document.getElementById('rect').cloneNode(true);
document.getElementById("svg").appendChild(newrect);
newrect.setAttribute("x", 100);
newrect.setAttribute("y", 100);
newrect.style.position = 'absolute';
var div = document.createElement('div');
document.body.appendChild(div);
div.id = 'div1';
var div1 = document.getElementById("div1");
div1.insertBefore(newrect, div1.firstChild);
}
Do you have a problem with the code? What’s the problem? It’s the continuation of the other question?
– Sergio
I think it creates the div, but my clone object disappears.
– akm
wants to create a new div with a
svg
in? if you can’t explain better pf...– Sergio
Yes that’s right. I want the object that was copied to be in a new div, created ('div1').
– akm
Is this what you’re looking for? http://jsfiddle.net/dgkcaf9q/
– Sergio
Yes it is, but I have a problem with the position. Because I have a div before the svg object. And it works if you take the position from the div. as in this case: http://jsfiddle.net/dgkcaf9q/4/
– akm
The problem is they’re on top of each other. If float already works: http://jsfiddle.net/dgkcaf9q/5/ If you explain in detail what you want to do you will get more help than if you ask in examples too specific...
– Sergio
Yes, what I want to do is move a svg object with the mousse, and when you drop create the clone in the position where the first one started. The problem is that the object does not go in the right position.
– akm
Can you put a jsFiddle with the full code you already have? Do you really want to do it with a svg or can it be another element?
– Sergio
yes, it has to be a svg http://jsfiddle.net/uLgkb8nr/
– akm
Would it be something like this then? http://jsfiddle.net/uLgkb8nr/1/
– Sergio
that’s right, thank you. but now the mousse is not in the middle of the object.
– akm