How do you put in a new line into a JavaScript alert box?
In the alert box, you can use “\n”, to break the sentence into a new line. If you want a linebreak in actual javascript, use the \n escape sequence. Do comment if you knew another way to break the sentence in a new line using JavaScript code or you have any doubts.
To create a line break in JavaScript, use “<br>”. With this, we can add more than one line break also.
The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS.
\n
will put a new line in - \n
being a control code for new line.
alert("Line 1\nLine 2");
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