Let's say I have textarea with this text:
- The first line is some text.
- second line, another text. The next line will be empty.
- (empty line)
- (empty line)
- last line here
As you can see, lines 3 and 4 are empty ( \n ). I need to get the exact structure of strings (with empty strings) and convert it to an array. Each row is an array element. This is my current code:
var lines = $('#q').val().split(/\n/); alert(lines.length);
It works fine in all browsers except IE. For some reason, the split () function ignores empty lines (3 and 4) in IE. Because of this, they are never passed to an array: s
Squeegy solution in the comments
Replace split(/\n/) with split("\n") - damn you IE!
source share