Sep 142010

Project Moved

This project has moved to BitBucket

  21 Responses to “Textarea Line Count: jQuery Plugin”

  1. Hi,

    great work. Can this be also extended to other elements like div’s, ul’s and so on?

  2. Really good man, appreciate your work, hope you improve with new features!
    I only had some problems with the blank lines, the plugin doesn’t count them when they are in the middle of the text.

    Can you check this? Tks again, Pedro.

    • Thanks for the feedback! Can you post an example of some text that won’t be counted correctly? I tried adding a few blank lines between the text in my demo ( but it seemed to work. I am definitely planning on updating it, hopefully soon. Among the changes I’ll make are increased accuracy. Thanks again for stopping by.

  3. Something like:

    “Enter some (line end)
    Text here (line end)
    and click the button to view stats

    (line end)”

    I tried with Chrome (last version) and Firefox (last stable). The demo counts 7 lines and only that. All the other values return 0;

  4. Hey man!

    I liked your plugin but for some reason it doesn’t work in my case. The code on works fine, but as soon I try to implement it on my stuff it breaks down.

    It turns out that it doesn’t calculate the width of span – so he returns 0. Anyway I tried to fix it, but no avail. So I turned to good old solution, and I’ve added another option value, “averageFontWidth”. You can guess what it does 😛

    PS: Some of my clients wanted to skin the text area, so I am developing skinning plugin for that. Your plugin is one of my dependences :)

    • Thanks for visiting! I’m glad you like the plugin! :)

      Some browsers are weird when it comes to calculating width on hidden elements; that might be why the width is returning 0. Also, I am planning on releasing a new version of my plugin soon (hopefully this month) so check back often! The API will be rewritten, so your plugin won’t work with the updated version. Looking forward to seeing it though.

  5. Nice little plugin. I easily managed to use it on multiple textareas, as follows:

          var $_this = jQuery(this);
          var r = jQuery.countLines($_this);
  6. Buggy:

    Not actually counting the number of lines. It’s still inconsistent. Please have a check

    • Thank you for the bug report.

      This is a known problem. Currently, the plugin doesn’t account for blocks of text that can’t be wrapped at any natural character. This behavior is different across browsers. In addition to that, there are several CSS attributes that modify how text wraps (take a look: Again, these work differently across browsers.

      I am hoping to fix this in the next release of the plugin. Unfortunately, I haven’t had time recently to work on any plugins.

  7. I think the lines (where the counting for the blank lines happens)

    if ($.trim(value) == “”)

    should be

    if ($.trim(v) == “”)

    for blank lines are counted correctly?

    Nice plugin though! Keep up the good work!

    P.S – I checked the JSFiddle since the download link doesn’t work (it says the plugin site is under development)

  8. Hi Colwin,

    Thanks for catching the bug :). Maybe I can push out a new version of the plugin tonight, while I’m still motivated. Anyway, jQuery’s plugin site was nuked (in error) by the admins. When I release the latest version, I’m going to migrate it to Google Code.



  9. […] I’ve released a mini-version (1.3) of Textarea Line Count. It fixes a single bug, described here: […]

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>