Search code examples
javascriptjquerynumberstextarealine

Display line number in textarea


I want to display the line number in a textarea like this is possible in jQuery:

enter image description here

I looked for answers on SO but I can't find what I want

Display current line and column number for a textarea

Limit number of lines in textarea and Display line count using jQuery

Also, the solution I tried from the JSFiddle provided from the comments show me the textarea like this:

enter image description here

which line 1234 is the first line and the second line is 5678


Solution

  • Download the plugin found here: http://alan.blog-city.com/jquerylinedtextarea.htm

    Usage:

    $(function() {
    
      // Target all classed with ".lined"
      $(".lined").linedtextarea(
        {selectedLine: 1}
      );
    
      // Target a single one
      $("#mytextarea").linedtextarea();
    
    });
    

    Fully functional demo: http://files.aw20.net/jquery-linedtextarea/jquery-linedtextarea.html (web.archive)