Hi all. I'm an experienced C and Java programmer that is trying my hand at Javascript. I'm writing some very basic trial programs and was curious why my document.write elements disappear when I add any kind of other javascript code.
For example, this works and I see the output.
Code:
<HTML>
<p id="intro">
Hello World!
</p>
<script>
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph</p>");
</script>
<button type="button" onclick=textChanger()> Don't click this button! </button>
</HTML>
But the output disappears when I add a simple var... why?
Code:
<HTML>
<p id="intro">
Hello World!
</p>
<script>
var switch;
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph</p>");
</script>
<button type="button" onclick=textChanger()> Don't click this button! </button>
</HTML>
I read that you can't have a document write inside a function or occur after the page has been created without clearing all the html, so I'm aware of that caveat. But this just removes my doc write calls, the html text is still there.
Thanks for the help!