Javascript tutorial, Article for, How to javascript append html string to element. I created following script putting the html at end of body tag.
javascript append html string to element
If you are using or following web 2.0(Table less HTML) standards for creating the HTMLs then this script will work 100%
Just Put this script in your HTML and see the html source. You will able to see the div id named “kapil” with the test content.
<script type=’text/javascript’> var kapil = document.createElement(‘div’); kapil.id = ‘form_kapil’; var all_divs = document.getElementsByTagName(‘div’); if (document.body.firstChild){ document.body.insertBefore(kapil, all_divs[all_divs.length] ); } else { document.body.appendChild(kapil); } var oldHTML = document.getElementById(‘form_kapil’).innerHTML; var newHTML = “test content”; //document.getElementById(‘form_kapil’).innerHTML = newHTML; var all_divs = document.getElementsByTagName(“div”); //alert(all_links[all_links.length - 1].innerHTML); all_divs[all_divs.length - 1].innerHTML = newHTML; </script>
Have fun!