Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVGSVGElement.children not working in IE11?

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?

like image 219
recursive Avatar asked Mar 19 '14 06:03

recursive


2 Answers

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.

like image 102
Thomas W Avatar answered Sep 27 '22 21:09

Thomas W


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.

like image 45
invertedSpear Avatar answered Sep 27 '22 23:09

invertedSpear