...

View Full Version : createTextNode for special characters



Kor
02-16-2005, 11:26 AM
document.createTextNode('·sometext')
or
document.createTextNode('\&middot\;sometext')

returns exactly ·sometext as string...

Any ideea how to create special characters in textNode?

hemebond
02-16-2005, 08:42 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>52522</title>
</head>
<body>
<script type="text/javascript">
var txt = document.createTextNode("This is a &middot; entity: " + String.fromCharCode(183));
document.body.appendChild(txt);
</script>
</body>
</html>

Kor
02-17-2005, 07:55 AM
Thanks.
Yes, even an unicode solution could be used. Till than I confess I have used a rather unelegant solution, such as:

var oTxt = document.createTextNode('sometext');
oTxt.innerHTML = 'specialchar'+oTxt.innerHTML;

liorean
02-17-2005, 09:21 AM
The most elegant solution would probably be to use a UCS-2 JavaScript escape - \uxxxx inside the string you send to createTextnode, where x is a hexadecimal digit.

Kor
02-17-2005, 09:40 AM
Yes, thanks, I have found till the end an unicode solution such as:

document.createTextNode('\u00B7sometext');

Skyzyx
02-25-2006, 07:22 PM
Check out my solution: http://www.codingforums.com/showthread.php?t=80593

Kor
02-25-2006, 08:52 PM
Thanks. This is quite an old thread of mine (over 1 year) I have learned since then how to use unicode escapes... Thanks anyway...

BubikolRamios
10-06-2006, 06:53 PM
readed all the post above, but cant figure out how to solwe this without innerHTML





//lest say taht arrElements[i] contains "TEST"

// does not work i.e returns '&nbsp;TEST'
someNode.appendChild(document.createTextNode("&nbsp;" + arrElements[i]));

//has no effest i.e returns 'TEST'
someNode.appendChild(document.createTextNode(" " + arrElements[i]));



thanks for tips

BubikolRamios
10-07-2006, 02:13 AM
did some googling, this works:




someNode.appendChild(document.createTextNode("\u00a0" + arrElements[i]));


anyone knows where can I get a list of of things like "\u00a0" ?

Kor
10-07-2006, 06:26 AM
oh, you have dig out again an old thread of mine. Yes, I have found out, the answer is on using unicode escapes:

here's a chart:
http://www.macchiato.com/unicode/chart/

and here's an online convertor:
http://people.w3.org/rishida/scripts/uniview/conversion



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum