开发者

Changing content using innerHTML with a non-standard element in Internet Explorer

开发者 https://www.devze.com 2023-03-15 04:48 出处:网络
I have the non-standard element <testele></testele> In every browser except IE, this bit of JavaScript will successfully change the content of the above element

I have the non-standard element

<testele></testele>

In every browser except IE, this bit of JavaScript will successfully change the content of the above element

document.getElementsByTagName("testele")[0].innerHTML = 'hi';

However, if I change the <testele> to just a <span> (in the HTML and the JavaScript), it now successfully changes the content of the element in every browser, including IE.

开发者_运维技巧

Is there any fix? I have searched around and tried a bunch to no avail.


Use document.createElement("testele") before it is rendered. This script must be included before the document encouters a <testele>:

http://jsfiddle.net/gilly3/LjwbA/

document.createElement("testele");
window.onload = function() {
    document.getElementsByTagName("testele")[0].innerHTML = 'hi';
};

If you try to do document.createElement("testele") after a <testele> has been parsed by the browser, it's too late.


Take a look at innerShiv, a Javascript plugin which aims to solve this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号