Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So, I have to get HTML of textarea and check whether it contains line break. How can i see whether it contain because the string return using val() does not contain and i am not able to detect it. I tried using .split(" ") but it gave the same result. How can it be done ?

One minute, IDK why when i add to textarea as value, it breaks and move to next line.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
328 views
Welcome To Ask or Share your Answers For Others

1 Answer

Line breaks in HTML aren't represented by or . 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 or (or ) for line breaks, so:

var text = $("#theTextArea").val();
var match = /
|
/.exec(text);
if (match) {
    // Found one, look at `match` for details, in particular `match.index`
}

Live Example | Source

...but that's just textareas, not HTML elements in general.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...