By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,568 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,568 IT Pros & Developers. It's quick & easy.

Determining (visual) text lines in DIVs through JavaScript

P: 1
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).

Jun 25 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
Welcome to TSDN!

Hmm.. that would be very difficult unless you have a fixed width font.
Jun 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.