Isabell
asked on
document.write() deleting all existing HTML
I am studying javascript now.(I am a beginner).
It says "Using document.write() after an HTML document is fully loaded, will delete all existing HTML"
When I run this code, I see the following result.
How come I still see existing html? ("My First Web Page" inside <h1> tag and <p> tag)
It says "Using document.write() after an HTML document is fully loaded, will delete all existing HTML"
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
document.write(5 + 6);
</script>
</body>
</html>
When I run this code, I see the following result.
How come I still see existing html? ("My First Web Page" inside <h1> tag and <p> tag)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@Stefan Hoffman,
From MDN Article (https://developer.mozilla.org/en-US/docs/Web/API/Document/write#wikiArticle)
From MDN Article (https://developer.mozilla.org/en-US/docs/Web/API/Document/write#wikiArticle)
Note: as document.write writes to the document stream, calling document.write on a closed (loaded) document automatically calls document.open, which will clear the document.
ASKER
Thank you!
See document.write() on MDN.