How to Line Breaks to JavaScript Alert?
Nov 04, 2020
Hi Guys,
In this example,I will learn you how to line breaks to javascript alert box.you can easy and simply create to line breaks to javascript alert box.
To add a new line to the content of alert box we are going to use \n backslash(n).
Example:
<!DOCTYPE HTML>
<html>
<head>
<title>
JavaScript |
New line in alert box.
</title>
</head>
<body style="text-align:center;"
id="body">
<h1 style="color:#af1bf9;">
NiceSnippets
</h1>
<p>
Click on the button to pop
alert box with added new line.
</p>
<button onclick="ns_Run()">
click here
</button>
<script>
var text =
"This is line 1\nThis is line 2";
function ns_Run() {
alert(text);
}
</script>
</body>
</html>
It will help you...
- How to set Date in setUTCHours() Method in JavaScript?
- How to Date sets UTC milliseconds in Javascript?
- How to Use push(), unshift(),pop() and shift() With Array in Javascript?
- How to Check if a Variable is a Number in Javascript?
- How To Format a Number Using Fixed - Point Notation in Javascript?
- How to Insert an Element into an Array in javaScript?
- How to remove duplicate elements from JavaScript Array?
- How to calculate years, months and days between two dates in javascript?