sirrobert
06-25-2007, 07:28 PM
Hey everyone. I've got some DIV elements containing arbitrary HTML that is entirely text (some of the childNodes are textNodes, some are strong or em tags containing textNodes, some are divs or spans containing textNodes, etc.).
It's pretty easy to get the entire text content of the div, but I'm having a tough time trying to figure out how to grab sub-sets of the text content spatially.
That is, let's say I've got a div with a string of text that breaks into four lines (because of the width of the div, etc). How can I capture just the second line, or just the third line, etc?
Is there some way to determine at which character (or word, or textNode, or ...?) the lines break? Is there some way to determine what is the first or last character of a line?
For the sake of simplicity, let's assume I have a div:
var dv = document.getElementById('myDiv');
and dv has the several lines of text (in arbitrary HTML).
Thanks,
sirrobert
It's pretty easy to get the entire text content of the div, but I'm having a tough time trying to figure out how to grab sub-sets of the text content spatially.
That is, let's say I've got a div with a string of text that breaks into four lines (because of the width of the div, etc). How can I capture just the second line, or just the third line, etc?
Is there some way to determine at which character (or word, or textNode, or ...?) the lines break? Is there some way to determine what is the first or last character of a line?
For the sake of simplicity, let's assume I have a div:
var dv = document.getElementById('myDiv');
and dv has the several lines of text (in arbitrary HTML).
Thanks,
sirrobert