'innerText' works in IE, but not in Firefox

前端 未结 15 1460
执念已碎
执念已碎 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:26

    myElement.innerText = myElement.textContent = "foo";
    

    Edit (thanks to Mark Amery for the comment below): Only do it this way if you know beyond a reasonable doubt that no code will be relying on checking the existence of these properties, like (for example) jQuery does. But if you are using jQuery, you would probably just use the "text" function and do $('#myElement').text('foo') as some other answers show.

提交回复
热议问题