View Full Version : creating a space ( & n b s p ) with createElement!!
ConfusedOfLife
03-29-2003, 12:54 PM
Hi
I'm trying to make a space with createElement. I'm using this code but it doesn't work as you can see there is no space between the 2 different set of characters. How can I achieve it?
<script>
v = document.createElement("span");
v.innerHTML = "FFFF";
document.body.appendChild(v);
e = document.createElement(" ");
document.body.appendChild(e);
v = document.createElement("span");
v.innerHTML = "HHHHH";
document.body.appendChild(v);
</script>
liorean
03-29-2003, 01:08 PM
There's two ways, one that is supported everywhere, on that isn't supported in any browser I know of.
document.createTextNode('\u00a0');
// Equivalent to &#0160; or &nbsp;
document.createTextNode(' ');
// I think this also should work, but then it might not as well.
document.createEntityReference('nbsp');
// This isn't supported, but it's the official way of adding an entity reference.
ConfusedOfLife
03-30-2003, 08:45 AM
Thanks! But you know something, as soon as I asked the question, I found out that I can have the same thing by a normal span, i.e.
myElement = document.createElement("span");
document.getElementById("something").appendChild(myElement);
myElement.innerHTML = "& n b s p & n b s p whatever";
Note: I hade to put a space between characters of & n b s p or this forum couldn't show it.
liorean
03-30-2003, 12:56 PM
Yes, but then you have to rememeber that even though innerHTML is supported in IE/Moz/Op7/Saf/Konq/iCab, it isn't in any ECMA, IETF, W3C, ISO or ANSI standard and thus may not be present in future browsers. If the W3C DOM WG ever chose to add an xml serialisation/deserialisation interface it might replace the innerHTML.
Originally posted by liorean
If the W3C DOM WG ever chose to add an xml serialisation/deserialisation interface it might replace the innerHTML.
DOM3 Load and Save. We get nifty DOMBuilder and DOMWriter interfaces. :)
http://www.w3.org/TR/2003/WD-DOM-Level-3-LS-20030226/load-save.html
ConfusedOfLife
04-02-2003, 08:29 AM
Well, thanks for your help. I don't know that much about these standards and the new things that will come out, but I hope the links in your footer help me find out more! Thank you. :o
F.N.G.
04-02-2003, 06:03 PM
Note: I hade to put a space between characters of & n b s p or this forum couldn't show it.
You can enter &nbsp; as &amp;nbsp;
-
liorean
04-02-2003, 06:17 PM
Jason, yes, there is that , but have you noted that even the browsers that implement DocumentLS doesn't support it in their HTMLDocument interface? That means, in effect, that you still can't use that interface to load or save.
(Oh, and I don't think even ie or moz have implemented DOMBuilder and DOMWriter. Moz have their XMLSerializer and DOMParser that are somewhat like those, and IE has XMLDOM/DOMDocument which is still further off.)
brothercake
04-02-2003, 06:35 PM
Interesting stuff ... but shurely even with full implementation of load and save, support for innerHTML is not going to be removed ... mehopes mozilla have learnt better than that ..?
liorean
04-02-2003, 08:29 PM
In fact, there's been some discussion about this among the developers. When they sometime in the future drop the html engine for one single engine, they aren't going to keep those proprietary features that have standards based equivalents.
Originally posted by brothercake
Interesting stuff ... but shurely even with full implementation of load and save, support for innerHTML is not going to be removed ... mehopes mozilla have learnt better than that ..?
I don't see it being removed. But emulating inner/outer HTML/Text is sooo trivial in Moz with setters and getters, I wouldn't be worried at all.
And with DOM3 L&S, you could create "innerXML", which may be more appropriate when dealing with XHTML anyway.
brothercake
04-02-2003, 08:43 PM
yeah right, that makes sense. Presumably then this kind of stuff will only work within the XML DOM?
zabano2000
11-06-2008, 10:23 AM
try the following:
myElement.appendChild( document.createTextNode( '\u00A0' ) );
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.