This code
alert("Hello again! This is how we" + "\n" + "add line breaks to an alert box!");
doesn't work. Firefox JavaScript console names error as "unterminated string literal" and points on " symbol before \n. I want to fire an alert with multi-line text. No jQuery please.
To add line breaks to JavaScript alert, use “\r\n”.
The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.
Haven't tested but does this work?
alert("Hello again! This is how we \n add line breaks to an alert box!");
This just happened to me... exactly. I needed to change it to \\n
instead of \n
.
alert("Hello again! This is how we"+"\\n"+"add line breaks to an alert box!");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With