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 824123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:03:13+00:00 2026-05-15T03:03:13+00:00

I am trying dynamically to append an <svg> element to an existing SVG island

  • 0

I am trying dynamically to append an <svg> element to an existing SVG island on an XHTML page (Firefox 3.6.3). And it is crashing the browser.

Done manually, this works as expected:

<svg xmlns="http://www.w3.org/2000/svg">
    <svg xmlns="http://www.w3.org/2000/svg">
        ...         
    </svg>
</svg>

However, if you dynamically add this element using JavaScript, the browser crashes. Simple example:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>SVG island example</title>
    <script type="text/javascript"><![CDATA[
        function crash( )
        {
            svgs = document.getElementsByTagNameNS( "http://www.w3.org/2000/svg", "svg" );

            for ( var i = 0; i < svgs.length; i++ )
            {
                var e = document.createElementNS( "http://www.w3.org/2000/svg", "svg" );
                svgs[i].appendChild( e );
            }
        }
    ]]></script>
</head>
<body>
    <svg id="mySVG" xmlns="http://www.w3.org/2000/svg">
    </svg>
    <button onclick="crash()">Crash Firefox</button>
</body>
</html>

Interestingly, if I do a getElementById, it works fine. Interesting, but not particularly helpful in my situation since I’m storing pointers to SVGDocuments. Example:

function doesntCrash( )
{
    var svg = document.getElementById( "mySVG" );
    var e = document.createElementNS( "http://www.w3.org/2000/svg", "svg" );
    svg.appendChild( e );
}

As far as I can tell, this is a Firefox bug. Does anyone have any insight into this matter?

UPDATED (solution):
As stated below, the issue was the “liveness” of the HTMLCollection returned by the getElementsByTagNameNS call which I mistook for a native array (tsk, tsk!) A quick hackaround would be to either store the array length in a variable, if you’re only appending. A better solution might be to copy the array contents to a native array, as described here. Here’s an updated using that method:

function doesntCrash( )
{
    var svgs = document.getElementsByTagNameNS( "http://www.w3.org/2000/svg", "svg" );

    // copy contents to native a static, array
    svgs = Array.prototype.slice.call( svgs );

    for ( var i = 0; i < svgs.length; i++ )
    {
        var e = document.createElementNS( "http://www.w3.org/2000/svg", "svg" );
        svgs[i].appendChild( e );
    }
}

Thank you Sergey Ilinsky for your quick response!

  • 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-15T03:03:14+00:00Added an answer on May 15, 2026 at 3:03 am

    The cause to your problem is likely hidden in liveness of the NodeSet returned by the getElementByTagName(NS) method call (which is not the case for querySelectorAll method, for example). So in your code you find all elements with name “svg” from SVG namespace, then start walking through this list and add new “svg” elements to the document that end up added to the collection you are walking too. Teoretically script simply should never exit, but in practice as you see browser crashes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to dynamically append an HTML-snippet to an existing Element with .append
I am trying to append a list element dynamically to already existing list. I've
I'm trying to dynamically spawn a video element on a page using JavaScript. JavaScript
I am trying to dynamically append some objects to a div and then programatically
I'm having issues trying to append dynamically created html inside a SimpleModal box (OSX
I'm trying to trigger a click event on a dynamically created element. I have
I am trying to dynamically append where conditions into a single expression-object, then pass
I am trying to get this class name dynamically in jquery: echo <div id=\maini\
OK I’ve been trying to append some checkbox’s to a div dynamically based on
I am trying to dynamically rewrite an entire page to a set of iframes.

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.