I have a function that removes spans that I have previously inserted in my xhtml.
My problem is, when it removes the span it doesn't join the string it contains with the strings around it.
So for example, I start with:
<p class="s6">
<span class="myClass">The</span>
" quick brown fox jumps over the lazy dog."
</p>
And then when I remove the span I get
<p class="s6">
"The"
" quick brown fox jumps over the lazy dog."
</p>
Whereas I want this:
<p class="s6">
"The quick brown fox jumps over the lazy dog."
</p>
the code I am using is this:
spansToRemove[i].parentNode.replaceChild(document.createTextNode(spansToRemove[i].innerHTML), spansToRemove[i]);
I have noticed that if I save and reopen the xhtml file, it turns into the version I want, but this seems quite hacky. And since I'm not normally a javascript programmer, I don't know if this is normal behaviour, or what the appropriate way to deal with it is?
That "createTextNode" in my code looks suspicious, but I can't find anythings else useful to replace it with.
The reason I don't like how it currently does it, is that it effects my ability to be able to select text freely.
This is happening in a UIWebview in an iOS app. Javascript not JQuery.
thanks