shreyaskudav Posted April 28, 2011 Share Posted April 28, 2011 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 More sharing options...
Ingolme Posted April 28, 2011 Share Posted April 28, 2011 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 More sharing options...
shreyaskudav Posted April 28, 2011 Author Share Posted April 28, 2011 Oh....I understood from your explanation better..Thanks.. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.