Connecting Tech Pros Worldwide Forums | Help | Site Map

space on text node DOM2

sudhaoncyberworld@gmail.com
Guest
 
Posts: n/a
#1: Dec 3 '05
Hi

var lbl=document.createElement('LABEL');
var txt=document.createTextNode('text');
lbl.appendChild(txt);

in above txt node i want a space infront of that

i tried below, but no use

var txt=document.createTextNode(' text');

any idea ???


Martin Honnen
Guest
 
Posts: n/a
#2: Dec 3 '05

re: space on text node DOM2




sudhaoncyberworld@gmail.com wrote:

[color=blue]
> var txt=document.createTextNode(' text');[/color]

It is a text node so pass in a string with the characters you want and
not some HTML entity references.
var txt = document.createTextNode(String.fromCharCode(160) + 'text');

--

Martin Honnen
http://JavaScript.FAQTs.com/
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#3: Dec 3 '05

re: space on text node DOM2


sudhaoncyberworld@gmail.com wrote:
[color=blue]
> var txt=document.createTextNode(' text');[/color]

Character entity references are defined by and in SGML-based markup
languages, not by and in programming languages like JS. Furthermore,
the above would not refer to a space character but to a "no-break space"
character in an SGML-based markup language. So you are looking either
for the space character

var txt = document.createTextNode(' text');

or the "no-break space" character, which would be either

var txt = document.createTextNode('*text');

(I am sending this in ISO-8859-1 encoding, so any ISO-8859-x encoding
should do) or

var txt = document.createTextNode('\xA0text');

or

var txt = document.createTextNode('\u00A0text');

Since escape sequences are more obvious, I suggest you use the latter.

Unicode escape sequences (`\u1234') are supported since JavaScript 1.3
(NN 4.06, 1998), probably since JScript 5.0 (IE/5.0 for Windows, March
1999), and all ECMAScript implementations (conforming to ECMA-262 of
June 1997).


PointedEars
sudhaoncyberworld@gmail.com
Guest
 
Posts: n/a
#4: Dec 6 '05

re: space on text node DOM2


thanks , i succeeded with u00A0

Closed Thread


Similar JavaScript / Ajax / DHTML bytes