The title may not seem that self-explanatory, but the question is actually pretty simple. Imagine the following code:
<div class="line">
Some text node here. <span>Some nodeType 3 here.</span>
More text here. <span>And here as well.</span>
</div>
Now, using javascript I'd like to delete the contents of the div. So something like:
function deleteContent(from, to) {
// Some code to execute here
}
and the result will be something like:
<div class="line">
Some text node here. <span>Some nodeType</span>
</div>
So basically, in theory, it's like using the slice
function div.innerHTML.slice(from, to)
except that this would only work if there were no tags within the div. I've already thought about creating a text range and deleting the contents with deleteContent but I don't know if it is the simplest way to go. What are your suggestions?
PS: I'd like to have a code that is neat and logical.
EDIT
As a response to Felix: Yes, I treat from and to as two integers. And for whitespaces, in my application I'll have to understand each whitespace seperately. That is,
are two characters.