I'm trying to count how many characters are displayed in the first line of a text which is wrapped because the width of the span is limited.
I know that counting the characters of a String can be done with "length", but I'm failing to get the first line.
Example:
#divone {
width: 80px;
overflow: hidden;
}
<div id="divone">
<p id="one">Some long text
<p>
</div>
Displayed the text appears as first line: "some long" and second line "text"
Expected output from JavaScript:
Some long
Pseudocode I thought to solve it:
Detect which is the last word before the text is wrapped
Look this word up in original text and retrieve a substring
Use
length()
to count characters of the substring.