+ 6
Why document.write() destroys any other html you may have had?
7 Respuestas
+ 5
Yashwanth Kumar I think it's because the "root" of the webpage is the "document" and if you command a bunch or line of out put to be written inside it, then, it will be assumed you don't give an Eff about what's in there previously.
+ 5
Thanks!
+ 4
Yashwanth Kumar How should I answer? This method functions like this because they've made it like this. 😂
It's a simple function, if it appended its argument to the end of document, the argument was going to go after </html> tag so it would make problems.
+ 3
Because it overwrites your document's text/code.
You should use other functions or methods if you don't want your page to become overwritten.
+ 3
Why does it overwrites the document text/code?
+ 2
name tage
+ 2
It has to do with the fact that you called the document object and asked it to run the write method with no input and you did not specify a specific tag to write to or encasulate it within a function to limit its scope. This method is “destructive” as it overrides what data was there in the first place.