Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Line Number In Text Area [duplicate]

Tags:

Possible Duplicate:
Find out the 'line' (row) number of the cursor in a textarea

I want to find out the line number that a user's cursor in on in a HTML textarea element.

Is this possible using javascript and jquery?

like image 914
Freelancer Avatar asked Sep 23 '12 14:09

Freelancer


1 Answers

This works with button click. Stolen from Find out the 'line' (row) number of the cursor in a textarea

​function getline() {     var t = $("#t")[0];     alert(t.value.substr(0, t.selectionStart).split("\n").length); }​ 

HTML

​<textarea rows="6" id="t"> there is no love in the ghetto so come here and get it </textarea> <input type="button" onclick="getline()" value="get line" />​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ 
like image 186
codingbiz Avatar answered Sep 20 '22 08:09

codingbiz