Jump to content

Difference between 2 scripts?


shreyaskudav

Recommended Posts

In Javascripting:Writing to The HTML Document

<html><body><h1>My First Web Page</h1><script type="text/javascript">document.write("<p>" + Date() + "</p>");</script></body></html>

Changing HTML Elements

<html><body><h1>My First Web Page</h1><p id="demo"></p><script type="text/javascript">document.getElementById("demo").innerHTML=Date();</script></body></html>

The output for both the scripts are the same....What difference does it makes??

Link to comment
Share on other sites

For this example, they're the same. One of them just writes the element onto the page while the other manipulates an element that already exists.The second method is useful because you are able to modify elements after the page has finished loading. document.write() can't be used after the page has loaded because it will clear the whole page.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...