Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6654267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:22:11+00:00 2026-05-26T01:22:11+00:00

I have an svg group which contains some elements, I want to clone the

  • 0

I have an svg group which contains some elements, I want to clone the group, problem is the function clones only one element of the group.
Here is the function

 <script type="text/ecmascript"><![CDATA[
    function clone(evt) {
        var cloneElement = evt.target.cloneNode(false);
        var newx = 100;
        var newy = 500;
        cloneElement.setAttributeNS(null,"x",newx);
        cloneElement.setAttributeNS(null,"y",newy);
        document.getElementById("layer1").appendChild(cloneElement);
    }

]]></script>

The svg looks something like

<g id="layer1" onclick="clone(evt)">
<rect>
<path>
<circle>
<circle>
</g>

The rectangle is like a container and what happens is that the function clones the rectangle and leaves the other elements.
So what is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:22:11+00:00Added an answer on May 26, 2026 at 1:22 am

    Two things:

    • cloneNode should be passed true if you want a deeply cloned tree, otherwise it will just clone one element
    • evt.target will always be the element where the event originated, and g elements are never hit directly, the mouse events just bubble up to there from the children. You can use evt.currentTarget instead if you want the element which is currently handling the event (in your case that would be the g element).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SVG which has multiple path elements contained within a group (it's
I have an SVG file that contains several elements (like path, circles, rectangles, etc.).
If I have inline SVG, including an element which has been scaled... <g transform=scale(sX,sY)>
I use the code below to have SVG embedded in HTML5. The only problem
I have an SVG element in which I have made a foreignObject. The foreignObject
right now I have a group of svg elements (circle, rect, path, etc.).The actual
I have a SVG file that I want to extend by adding onclick handlers
I have an SVG map of the world, and I want to colour each
I have an svg file where I want to remove points if the x
I have a php script (generator.php) which generates certain HTML/XML/SVG depending on various conditions.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.