How to get particular lines string length from DOM element by using javascript/jquery

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to get particular lines string length from DOM element by using javascript/jquery



I have a string like this (hello how are you? hello how are you? hello how are you? hello how are you?). I am rendering this string in DOM element with 80px of width.



I am counting number of string lines by using below code. Now it returns number of lines displayed in UI.



Now i need to count second line's string length. How to get second line's string length? is there any possible solution to do this?




function numberOfLines() {
var divHeight = document.getElementById('content').offsetHeight
var lineHeight = parseInt(document.getElementById('content').style.lineHeight);
var lines = divHeight / lineHeight;
alert("Lines: " + Math.round(lines));
}


<body onload="numberOfLines();">
<div id="content" style="width: 80px; line-height: 20px">
hello how are you? hello how are you? hello how are you? hello how are you?
</div>
</body>





What do you mean by "second lines"?
– Cata John
1 hour ago





1st line string is "hello how" and 2nd line string is "are you?" and vise versa.
– Rajkumar A
1 min ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived