How To Check If Cursor Is On An Empty Line Inside Textarea?
How do I check if the cursor is on an empty line inside a textarea? I don't care about word wrapping. I care about lines that were created by hitting Enter. $('textarea').on('chang
Solution 1:
The following should work, but won't in older versions of IE.
// on(..., function() {if( this.value.substr(0,this.selectionStart).match(/(?:^|\r?\n\s*)$/)
&& this.value.substr(this.selectionStart).match(/^(?:\s*\r?\n|$)/)) {
console.log("empty");
}
EDIT search now explicitly looks for a newline, with further whitespace optional.
Post a Comment for "How To Check If Cursor Is On An Empty Line Inside Textarea?"