Is it possible at all to count the number of characters for a single line. Let's say that we have a paragraph of 5 lines, is it possible to count the number of characters of each line. Everything I was able to find so far counts the number of characters for the entire paragraph...
Asked
Active
Viewed 848 times
1 Answers
2
this should work
var lines = $("yourDiv").text().split("\n");
$.each(lines, function(n, elem) {
console.log(elem.length);
});

Genjuro
- 7,405
- 7
- 41
- 61
-
I tried your suggestion but the console returns the number of characters of the entire text. My text is a paragraph within a contentEditble div. _Edit_ What I mean is that the lines break because of the width of the container div, there is no "physical" line break. I guess what I'm asking for is impossible to achieve. – user495915 Oct 16 '11 at 14:11
-
i think you can estimate the length at wich the line breaks implicitely , and split your div according to each line length. – Genjuro Oct 17 '11 at 09:40