Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting no break space in DOM textnode 1

Status
Not open for further replies.

Steviebone

Programmer
Jul 17, 2007
10
US
How do u insert a literal such as   in a DOM textnode using javascript?

In this code:

var sp1_sup = document.createElement("sup");
var sp1_suffix = document.createTextNode(" (" + zno + ")" );
sp1_sup.appendChild(sp1_suffix );

the literal string is printed.. how do I get the textnode to recognize the no break space
 
You can use your method if you first convert the entity into octal (for some reason):
Code:
var sp1_suffix = document.createTextNode("[!]\u00a0;[/!](" + zno + ")" );
Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
you could also write it out like this

document.write(" ");

Code:
var sp1_suffix = document.createTextNode(" (" + zno + ")" );


[monkey][snake] <.
 
monksnake... what browser did you test that in - because it's no good in Firefox [smile]

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Hmm I did it in good ol IE6, I'll take a look and see what it does in FF.

[monkey][snake] <.
 
Strange, this is exactly what I have:
Code:
<script type="text/javascript">
   document.write("&#38;&#35;160;");
</script>

in a DOCTYPE and it works for me, even in FF.

[monkey][snake] <.
 
hahaha, nevermind, I'm making the literal be printed. not the space DUH, but that's what I was going for. Too bad that wasn't the answer to the question that was asked.

[monkey][snake] <.
 
Here we go, I knew I'd find another way:

Code:
var sp1_suffix = document.createTextNode(String.fromCharCode(160) + "(HELEEO)" );

[monkey][snake] <.
 
muchas gracias seniors!

wow, never seen such quick response... it is much appreciated

Code:
var sp1_suffix = document.createTextNode(String.fromCharCode(160)+"(" + zno + ")" );

seemed to to do the trick... haven't tested it thoroughly in every browser yet tho...

thanks monsake!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top