Jquery – Count characters on single line in contentEditable DIV

862 Views Asked by At

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...

1

There are 1 best solutions below

2
On

this should work

var lines = $("yourDiv").text().split("\n");
$.each(lines, function(n, elem) {
            console.log(elem.length);
          });