Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>Using element.innerHTML is incorrect as SVG elements shouldn't have a innerHTML property

Is that definitely the case? Chrome, Firefox, and Safari all return a value for the innerHTML property of an element in an SVG document.

This W3C spec [0] specifically mentions XML documents in addition to HTML documents. And as I understand it, it seems like embedded SVG elements also inherit from the Element interface which includes InnerHTML.

IE11 might also be correct, following an older spec, but I don't think you can jump to the conclusion that Chrome is wrong just because the property is called innerHTML.

[0] https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin



That is interesting.

I assumed that innerHTML must have been wrong because textContent works in all the browsers I have tried it on whereas innerHTML doesn't work. A cursory search textContent vs innerHTML seemed to suggest textContent was the correct way.

It looks like it isn't a simple case of IE11 (I haven't had a chance to test on 9 & 10 yet) being correct and the others being incorrect. Thanks for the info.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: