I need to extract a HTML-Substring with JS which is position dependent. I store special characters HTML-encoded.
For example:
HTML
<div id="test"><p>lösen & grüßen</p></div>
Text
lösen & grüßen
My problem lies in the JS-part, for example when I try to extract the fragment
lö
, which has the HTML-dependent starting position of 3
and the end position of 9
inside the <div>
block. JS seems to convert some special characters internally so that the count from 3
to 9
is wrongly interpreted as "lösen
" and not "lö
". Other special characters like the &
are not affected by this.
So my question is, if someone knows why JS is behaving in that way? Characters like ä
or ö
are being converted while characters like &
or
are plain. Is there any possibility to avoid this conversion?
I've set up a fiddle to demonstrate this: JSFiddle
Thanks for any help!
EDIT:
Maybe I've explained it a bit confusing, sorry for that. What I want is the HTML:
<p>lösen & grüßen</p>
.
Every special character should be unconverted, except the HTML-Tags. Like in the HTML above.
But JS converts the ö
or ü
into ö
or ü
automatically, what I need to avoid.
` tags?
– Roko C. Buljan Nov 22 '12 at 14:06