space on text node DOM2

  • Thread starter sudhaoncyberworld
  • Start date
S

sudhaoncyberworld

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 ???
 
M

Martin Honnen

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

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');
 
T

Thomas 'PointedEars' Lahn

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top