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?
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With