Here is an example:
<div><span style="font-size:15px;">some text here which is </span>
<span style="color:red;">split automatically by the browser.</span></div>
which the browser renders as (with styles of course):
some text here which is split
automatically by the browser.
I am building up a javascript application which has to understand the last word in each line (split in this case). Currently I am using the CSS white-space property to deal with overflow text. Therefore, the browser will not give me a clue about where it does break the line. So, what would be a nice function to understand the last word in each line?
EDIT
I am using pure-javascript, so jQuery would not be an option and the white-space property is applied to the div. So actually, think the div as a line renderer.
You can rewrite the whole sentence word-by-word keeping track of the height changes. Here is some explanation via code:
HTML:
Script:
This will log the last words of each line to the console except the last line. I leave that to you. The nice thing about this solution is that even after a window resize it works correctly.
By the way, Yi Jiang deserves all the credit for his answer to this question here on SO.