Advertise on Site! You can Advertise on our site. Find out More

How to use document.write and innerhtml

3 Flares Twitter 3 Facebook 0 Google+ 0 StumbleUpon 0 LinkedIn 0 Buffer 0 Filament.io 3 Flares ×

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

3 Flares Twitter 3 Facebook 0 Google+ 0 StumbleUpon 0 LinkedIn 0 Buffer 0 Filament.io 3 Flares ×
  • Pingback: uberVU - social comments

  • http://hubpages.com/hub/Smokeless-cigarettes-to-quit-smoking Smokeless cigarettes

    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!

  • http://www.supremesearch.net Sunni Finken

    Sweet post.

  • http://uautocity.info Johnny Paywa

    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?

  • http://Crafts-Hobbies.info Florinda Wolfson

    I’ve been checking your blog for a while now, seems like everyday I learn something new :-) Thanks

  • http://top-skincare.info Pete Widrick

    Awesome post. I so good to see someone taking the time to share this information

  • http://ecommerce-web.info Isreal Tacheny

    Intriguing post. I have been searching for some good resources for solar panels and discovered your blog. Planning to bookmark this one!

  • http://paid2surveys.info Felipa Giessinger

    This post makes a lot of sense !

  • http://affiliatetown.info Hai Goring

    Of course, what a great site and informative posts, I will add backlink – bookmark this site? Regards, Reader

  • http://collegeswith-physicaltherapymajors.blogspot.com/ Joaquin Pov

    Great read. Thanks for the info!

  • http://www.ifoodlinks.com/ Inge Ridlen

    Good! Thank you! I always wanted to write in my site something like that. Can I take part of your post to my blog?

  • http://www.ifoodlinks.com/ Malcolm Geigel

    I’ve just started off a blog, the knowledge you give on this site has aided me extremely. Thank you for all your time & work.

3 Flares Twitter 3 Facebook 0 Google+ 0 StumbleUpon 0 LinkedIn 0 Buffer 0 Filament.io 3 Flares ×