I'm trying to create a method for my framework that'll do something with the text inside the element, but having an issue in FF and IE.

<div id="myDiv" style="border: 1px solid red;">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas suscipit lacus non hendrerit cursus.
</div>

<script>
    console.log(document.getElementById('myDiv').hasOwnProperty("innerHTML"));
</script>

This returns false in FF and IE. Though it returns true in Chrome. And idea why is that?

有帮助吗?

解决方案

As of Chrome 43, per spec, the innerHTML property is on Element.prototype (as a getter/setter pair), not on element instances. Firefox and IE implement the spec properly. Chrome violates the spec, because they claim the call from JS to C++ would be slower if they put it on the prototype (though in practice, SpiderMonkey manages to make the call faster than V8 for DOM property getters).

For more info about this change see: https://developers.google.com/web/updates/2015/04/DOM-attributes-now-on-the-prototype?hl=en

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top