See fiddle: if you press Enter
in the textarea on a recent Mac, the newline
character appears to be represented by \r
, which would be in direct contrast to the answers to this, this and this question and to Wikipedia. To summarise these links:
\r
represents a line break on old Macs (OS 9 and before)\n
represents a line break on UNIX systems (OS X, Linux)\r\n
represents a line break on Windows.
When I press Enter in the JSFiddle, I get the following result (OS X 10.11.6):
textarea: \r
span: \n
This behaviour took a long time to figure out and seems illogical. What could be the underlying rationale?
See fiddle: if you press Enter
in the textarea on a recent Mac, the newline
character appears to be represented by \r
, which would be in direct contrast to the answers to this, this and this question and to Wikipedia. To summarise these links:
\r
represents a line break on old Macs (OS 9 and before)\n
represents a line break on UNIX systems (OS X, Linux)\r\n
represents a line break on Windows.
When I press Enter in the JSFiddle, I get the following result (OS X 10.11.6):
textarea: \r
span: \n
This behaviour took a long time to figure out and seems illogical. What could be the underlying rationale?
Share Improve this question edited May 23, 2017 at 12:25 CommunityBot 11 silver badge asked Jul 31, 2016 at 21:22 BartBart 1,6092 gold badges14 silver badges29 bronze badges 2-
1
your fiddle looks at the wrong thing, try testing the
.value
of the textarea... – dandavis Commented Jul 31, 2016 at 21:39 - 1 Fwiw unix.stackexchange./questions/349214/… – Dominik Teiml Commented May 18, 2022 at 17:22
1 Answer
Reset to default 11I believe you're confusing two things:
- What character code does pressing the enter key yield?
- What line ending is used on which platforms?
As far as I know, the answer to #1 is 13 (ASCII carriage return, "\r") for all platforms.
Do you have a platform where this is not what you're seeing?