Dynamic HTML: The Definitive Reference, 2rd Ed.Dynamic HTML: The Definitive ReferenceSearch this book

12.9. Special (Escaped) String Characters

\charNN 2 IE 3 ECMA 1

JavaScript provides a mechanism for including common whitespace characters (sometimes called control codes) inside strings, as well as symbols that otherwise conflict with string representation. The key is the backslash character (\), followed immediately by a single character with a special meaning. The following table shows the recognized escaped characters and their meanings.

Escape sequence

Description

\b

Backspace

\t

Horizontal tab

\n

Line feed (new line)

\v

Vertical tab

\f

Form feed

\r

Carriage return

\"

Double quote "

\'

Single quote '

\\

Backslash

These characters come in handy for alert, confirm, and prompt dialog box text. For example, if you want to display multiple paragraphs with a blank line between them in an alert box, you would insert line feed characters:

alert("First paragraph.\n\nSecond paragraph.")

Note that these characters apply to strings, and do not influence HTML content formatting for carriage returns.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.