greenflame wrote:
<div id="textHolder"></div>
<input type="button" value="Add some text" onclick="
addText( 'Here is some text', 'textHolder' );
">
<script type="text/javascript">
function addText( str, elID ){
var aDiv = document.getElementById( elID );
This line looks for a div with an id of elID.
var oTxt = document.createTextNode( str );
Then a text node is created with the text in str
aDiv.appendChild( str );
And then the text node is appended to the div. All there is to 'see'
is the text - 'Here is some text'.
[...]
Ok... I tryed it with html in the string but when I looked at the page
it just showed the text
and it did not parse any of it as html. How do I get it do do this?
There is no HTML to parse. You are using DOM methods to create
elements, not HTML.
If you want a tutorial, go through the stuff at w3schools:
<URL:http://www.w3schools.com/htmldom/default.asp>
It's a bit old and IE centric, but it will get you started. Also
check through the archives here to find things you are after and read
the FAQ.
<URL:http://www.jibbering.com/faq/>
If you want to see the content of the page after you've done your DOM
stuff, read the thread here:
<URL:http://groups-beta.google.com/group/comp.lang.javascript/browse_thread/thread/a108f8cb58111ece/d6a776db34c1be8d?q=innerHTML+view+document&rnum=4& hl=en#d6a776db34c1be8d>
--
Rob