My goal is to get the length of textContent of first 3 lines in a div. Ex:
<div id="content" style="width: 100%;
line-height: 20px">
<p>hello how are you?</p>
<p>hello how are you too?</p>
<p>hello how are you john? </p>
<p>hello how are you sphia?</p>
</div>
I'm able to count number of lines contained in the div using:
function countLines() {
var el = document.getElementById('content');
var divHeight = el.offsetHeight
var lineHeight = parseInt(el.style.lineHeight);
var lines = divHeight / lineHeight;
alert("Lines: " + lines);
}
however I want to know wether there is a way to find the length of text of the first 3 lines, in above case:
<p>hello how are you?</p>
<p>hello how are you too?</p>
<p>hello how are you john? </p>
lets say I do:
var lines = countLines(); // 4
if (lines > 3) {
test = document.getElementById("content").textContent.length;
// get the length of first 3 lines
}
is this possible in javascript ?