Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Line Numbers To HTML Textarea

Tags:

html

textarea

I have a <textarea /> as in the code below. How do I display the line numbers on the left hand side of it?

Is there a jQuery plugin?

<TEXTAREA name="program" id="program" rows="15" cols="65" ></TEXTAREA> 
like image 837
Hulk Avatar asked Jan 03 '10 15:01

Hulk


People also ask

How do I add line numbers to textarea in HTML?

Style the Textarea We can use the built-in counter function in CSS in combination with counter-increment to add the line numbers. The counter function expects an arbitrary name that we define for counter-increment . This is going to add the content inside a ::before pseudo-element.

How do I show line numbers in HTML?

When you want to display a code listing with HTML, you use a <pre> tag in order to indicate that the text is preformatted, then inside one or multiple <code> tags to specify it is a code.

How do you add a line in textarea?

To add line breaks to a textarea, use the addition (+) operator and add the \r\n string at the place where you want to add a line break, e.g. 'line one' + '\r\n' + 'line two' . The combination of the \r and \n characters is used as a newline character. Here is the HTML for the examples in this article. Copied!

How do I change the number of lines in a textarea?

The variable lineHeight is set to the numeric value of the style property line-height of our TextArea . The variable tr represents the text in our TextArea and holds its dimensions as bounding properties. We divide the property boundingHeight by lineHeight to get the number of lines our text occupies.


1 Answers

There is Lined TextArea (Link no longer valid, see mirror) plugin for jQuery by Alan Williamson
MIT License
jQuery 1.3+

like image 80
anatoly techtonik Avatar answered Sep 24 '22 00:09

anatoly techtonik