DOM (Document Object Model) – Write elements

With JavaScript you can:
– Change Output Stream
– Change the HTML content
– Change the Value of an Attribute

<!DOCTYPE html>
<html>
<body>

<p id="p1"></p>
<img id="image" src="smiley.gif">

<script>
var txt="Hello World! This text is created by Javascript!";

// Changing Output Stream
// Warning: Never use document.write() after the document is loaded. It will overwrite the document.
document.write(txt);

// Changing HTML Content
document.getElementById("p1").innerHTML=txt; // It changes the content of id="p1" element

// Changing the Value of an Attribute
document.getElementById("image").src="landscape.jpg"; // it changes the src of id="image" element

</script>

</body>
</html>

My official WebSite >