In this short article I will explain how to add multiple line breaks (<BR />) to JavaScript Alert message box.
If you want to add a new line to the text displayed inside the JavaScript alert you will need to make use of the following new line character.
Here’s a simple example where I am illustrating how to display multiple lines in a JavaScript Alert message box.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type = "text/javascript">
function DisplayMultiLineAlert() {
var newLine = "\r\n"
var message = "ASPSnippets offers free ASP.Net"
message += newLine;
message += "Code Snippets, Tutorials, Articles,";
message += newLine;
message += "Technical Stuff, Tips, Solutions";
message += newLine;
message += "and much more.";
alert(message);
}
</script>
<input type = "button" value = "Show Message" onclick = "DisplayMultiLineAlert()" />
</body>
</html>
Demo
Downloads