When should one use [removed] and when [removed] in JavaScript

后端 未结 3 2129
孤独总比滥情好
孤独总比滥情好 2020-12-05 20:05

Is there a general rule, when one should use document.write to change the website content and when to use .innerHTML?

So far my rules were:

3条回答
  •  时光说笑
    2020-12-05 20:25

    innerHTML and document.write are not really comparable methods to dynamically change/insert content, since their usage is different and for different purposes.

    document.write should be tied to specific use cases. When a page has been loaded and the DOM is ready you cannot use that method anymore. That's why is generally most used in conditional statements in which you can use it to syncronously load external javascript file (javascript libraries), including

提交回复
热议问题