0
  <div id="line_numbers"></div>
  <textarea cols="65" rows="15" name="comments" id="comments"></textarea>
  <textarea cols="65" rows="15" name="matches" id ="matches"></textarea>

there are many examples out there( Html adding line numbers to textarea ) but i just want to implement line numbers for a text area using jquery.Please let me know how to go about it.Any help would be really appreciated

Community
  • 1
  • 1
Rajeev
  • 44,985
  • 76
  • 186
  • 285

2 Answers2

2

I haven't looked into any plugins. However, here's a simple way for you to get started.

CSS:

#line_numbers {clear:both; float: left; text-align: right}

jQuery:

   $("#comments").change(function() {
     var comment_lines = $("#comments").val().split('\n');      
     $("#line_numbers").html('');
     for(i = 0; i < comment_lines.length; i++) {
        $("#line_numbers").html($("#line_numbers").html() + (i+1) + "<br/>");
     }
   });
Jose Basilio
  • 50,714
  • 13
  • 121
  • 117
1

I've never used it, but there's also the JQuery Lined TextArea plugin.

Ken Redler
  • 23,863
  • 8
  • 57
  • 69