document.write and innerhtml both the functions are useful to adding the dynamic content in in Document.
Both function are many times used by developer in javascript functions, Ajax calls, Web services and many JS libraries.
So We need understand the similarities and differences and limitation about document.write and innerhtml.
First whenever and where you calls document.write function that more important.
Here I am going to show you how to use the document.write first.
<script type="text/javascript">
var hello_world = function() {
document.write('Wordpressapi is good website'); // print hello world in DOM
var mytext = "Wordpressapi is best website";
document.write(mytext); // print again through variable.
}
</script>
Using above code you can print or execute the so much HTML content in DOM.
Here I am going to show you how to use the innerHTML in DOM.
<script type="text/javascript">
document.getElementById('sample_Div').innerHTML="Wordpressapi is good website"; // add simple text
//document.getElementById('sample_Div').innerHTML="<img src=sample.jpg></img>"; // add image
</script>
Note: In your document “sample_Div” id with div need to be present.
put following code in your document.
<div id=\"sample_Div\"> Sample Text </div>
Loading iframe using innerhtml is the best techniqe and solution for web services and cross domain calls.
document.getElementById('sample_Div').innerHTML = "<iframe src='http://images.wordpressapi.com/'></iframe>";
Both the techniques are stand for as per situation and use
Incoming search terms:
- document write innerhtml
- document write or document inner html
- document write to innerhtml
- how dose innerHTML differ from Documenbt wrte







Pingback: uberVU - social comments
I ended up your site a couple weeks back and I just can’t get enough! Please keep writing!
Admiring the time and effort you put into your blog and detailed info you provide! I am going to bookmark your blog and have my children check up the following generally. Thumbs up!
Sweet post.
I REALLY liked your post and blog! It took me a minute bit to find your site…but I bookmarked it. Would you mind if I posted a link back to your post?
Thanks for posting. Good to see that not everyone is using RSS feeds to build their blogs
I was just having a conversation over this I am glad I came across this it cleared some of the questions I had.
I’ve been checking your blog for a while now, seems like everyday I learn something new
Thanks
Awesome post. I so good to see someone taking the time to share this information
Interesting read, perhaps the best article iv’e browse today. We learn everyday cheers to you!
Intriguing post. I have been searching for some good resources for solar panels and discovered your blog. Planning to bookmark this one!
This post makes a lot of sense !
Of course, what a great site and informative posts, I will add backlink – bookmark this site? Regards, Reader
Great read. Thanks for the info!
Thanks for posting. Good to see that not everyone is using RSS feeds to build their blogs
I REALLY liked your post and blog! It took me a minute bit to find your site…but I bookmarked it. Would you mind if I posted a link back to your post?
I would like to say “wow” what a inspiring post. This is really great. Keep doing what you’re doing!!