By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

it did not work

P: n/a
<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 );
var oTxt = document.createTextNode( str );
aDiv.appendChild( str );
}
</script>

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?

Aug 6 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
greenflame wrote:
function addText( str, elID ){
var aDiv = document.getElementById( elID );
var oTxt = document.createTextNode( str );
aDiv.appendChild( str );


That line should be:
aDiv.appendChild(oTxt);

--
Isofarro.
FAQ: http://www.html-faq.com/
isolani: http://www.isolani.co.uk/blog/
Aug 6 '05 #2

P: n/a
O yea I noticed that so i changed it. sorry for not mentioning it. But
it still does not show the html. :(

Aug 6 '05 #3

P: n/a
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
Aug 7 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.