views:

61

answers:

1

This happens in Firefox, but not in Google Chrome.

I create an SVG 'Image' tag in an svg-web canvas like this:

im = document.createElementNS(svgns, 'image');
im.setAttributeNS(xlinkns, 'href', g.href);
canvas.appendChild(im);

And if I look in firebug or chrome's debugger, the svg shows up self-closed like this:

<image xlink:href="..." />

But if I then print the parent of the svg element's innerHTML, it returns this:

<svg><image xlink:href="..."></svg>

Note that the image tag is now unclosed, which causes errors down the line. Have I discovered a bug, or am I doing something wrong? And, probably much harder, is there a way in JavaScript to check and fix the tag?

A: 

HTML does not require empty tags to have a ending close. Even if the document were in XHTML I am not sure that it would return valid XML from the innerHTML property.

Edit: Mozilla Developer Center documentation for innerHTML says that you should not depend on what you get back out of the innerHTML and suggests some libraries as replacements specifically for use with XML.

lambacck
I am aware. Still, it shows up in the HTML viewer the first way, and shouldn't the default implementation be the 'correct' one? If this is intended, wouldn't this mean that the javascript DOM methods don't really work for XHTML?
colinmarc
The way the tool displays it does not imply anything about how the data will come out of innerHTML. Firebug is a completely separate project from Firefox. What is it you actually want to accomplish? Do you want to confirm if this is a bug? Do you want to do something with the data out of innerHTML? It is not that innerHTML generates an unclosed tag, it is that HTML not only does not require /> it does not allow it, so Firefox is providing valid HTML from its innerHTML property.
lambacck
your edit led me to the innerDom package, which is what I want, I think. thanks
colinmarc