質問

I have a very simple jsfiddle here:

http://jsfiddle.net/9uS3u/

It consists of this html:

<svg></svg>

And this javascript:

alert(document.getElementsByTagName("svg")[0].children);

I expect it to alert something like "[Object HtmlCollection]". In IE 11 though, it gives "undefined". It seems that the children property is not defined on SVGSVGElement despite claims on the internet that IE 11 does support svg. What gives?

役に立ちましたか?

解決

I think the answer is that the children property is not yet officially part of the DOM specifications, where you'll find childNodes on the Node interface, but not children (neither on the Element interface). For further info (especially the difference between children and childNodes), have a look at this other answer.

他のヒント

In my research so far, svg is supported by IE as an SVGGElement, where as the children property is part of an HTMLCollection element. All the other browsers seem to treat SVGs as HTMLCollections. Why IE treats SVG differently than other browsers, I can't answer, but it is annoying and causing me to write all sorts of work-arounds to manipulate SVGs on the fly.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top