I have the value of a textarea, how do I find out if the textarea starts off with a carriage return? I read some posts and understand that the CR is represented as \n? But how can I find out if the very first thing (character?) in the textarea is a return? If not, how can I add one to it?
I'm picturing something like this:
var content = $("#myTextArea").val();
if (content.charAt(0)=="\n"){
//do nothing
}
else
{
content.before("/n")
}
Apparently it's wrong but how should I do it?
jQuery's before
inserts elements, it does not change the value of a textarea, you could do this
$("#myTextArea").val(function(_, v) {
return (v.charAt(0) === "\n" ? "" : "\n") + v;
});