Line breaks in HTML aren’t represented by \n
or \r
. They can be represented in lots of ways, including the <br>
element, or any block element following another (<p></p><p></p>
, for instance).
If you’re using a textarea
, you may find \n
or \r
(or \r\n
) for line breaks, so:
var text = $("#theTextArea").val();
var match = /\r|\n/.exec(text);
if (match) {
// Found one, look at `match` for details, in particular `match.index`
}
Live Example | Source
…but that’s just textarea
s, not HTML elements in general.