JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 15th, 2008, 08:56 PM
habileneous habileneous is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 1 habileneous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 20 sec
Reputation Power: 0
CreateTextNode - can't render html?

hey, i've got a small problem with html tags showing up when i dont want them to...

i'm using a script to append a variable to a page:

Code:
var middle = document.createElement("div");
middle.setAttribute("id","newid");
var desctext = document.createTextNode(answer);
middle.appendChild(desctext);
var first = document.getElementById("first");
var parentDiv = first.parentNode;
parentDiv.insertBefore(middle,first);


the problem i have is with the variable "answer" - here's its code:

Code:
var answer;
answer = "<br>You scored <b>" +score+ "</b> out of 10";
answer = answer + "<br>1: "+feedback1;
answer = answer + "<br>2: "+feedback2;
answer = answer + "<br>3: "+feedback3;
answer = answer + "<br>4: "+feedback4;
answer = answer + "<br>5: "+feedback5;
answer = answer + "<br>6: "+feedback6;
answer = answer + "<br>7: "+feedback7;
answer = answer + "<br>8: "+feedback8;
answer = answer + "<br>9: "+feedback9;
answer = answer + "<br>10: "+feedback10;


with 'document.write" the variable gets formatted properly and all the html tags are read and rendered, howerver when i pass the variable to the createTextNode() method, all of the html tags show up as part of the string... is there a way around this? does anyone know of a solution that would read/render the html properly?

thanks!

Reply With Quote
  #2  
Old May 15th, 2008, 09:06 PM
lnxgeek lnxgeek is offline
I AM A GOLDEN GOD
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Apr 2003
Location: Camarillo, California
Posts: 5,932 lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level)lnxgeek User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 3 Days 16 h 44 m 38 sec
Reputation Power: 1165
The createTextNode method does just that - creates a node of type "Text".
You can use the non-standardized (but frequently used) innerHTML property, e.g.
Code:
document.getElementById("yourContainerDiv").innerHTML= answer;
__________________
"Seriously, we're not a search engine, we're actual people." ~ ManiacDan

BookMooch.com : Give books away. Get books you want.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > CreateTextNode - can't render html?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap