So I'm working on a micro lib, html.js, and basically it creates text nodes with document.createTextNode
but when I want to create a text node with a b
I get a b
so I'm wondering how to escape the &
char, without using innerHTML ideally..
Javascript supports the \uXXXX
notation, so in the case of a non-breaking space, that would be \u00A0
.
document.createTextNode('a\u00A0b');
That's as far as you can get. It's a text node, consisting only of text, and there's no difference between texts created from entity references or from normal characters.
If that's not what you want, you should take a second look at innerHtml. Can't you read it, modify it and put it back?
replace(' ', ' ')
manually, but there is no built in routine that does all of them. You'll need an exteral library for that - Mr Lister 2012-04-06 06:04
There's not much functionality in js to encode/decode html entities. Seems like there some libraries out there, though, that can help you achieve this. Here is one I found on goodle.. haven't tried it, but you can check it out, or look for others.
http://www.strictly-software.com/htmlencode
&
- James Montagne 2012-04-05 18:19