'innerText' works in IE, but not in Firefox

前端 未结 15 1455
执念已碎
执念已碎 2020-11-21 05:01

I have some JavaScript code that works in IE containing the following:

myElement.innerText = \"foo\";

However, it seems that the \'innerTex

15条回答
  •  南笙
    南笙 (楼主)
    2020-11-21 05:30

    As per Prakash K's answer Firefox does not support the innerText property. So you can simply test whether the user agent supports this property and proceed accordingly as below:

    function changeText(elem, changeVal) {
        if (typeof elem.textContent !== "undefined") {
            elem.textContent = changeVal;
        } else {
            elem.innerText = changeVal;
        }
    }
    

提交回复
热议问题