How to Line Breaks to JavaScript Alert?

JavascriptWeb DevelopmentFront End Technology

To add line breaks to JavaScript alert, use “\r\n”. In the following example, we will see how to display text in JavaScript alert.

Example

 Live Demo

<html>
   <body>
      <script>
         function DisplayAlert() {
            var newLine = "\r\n"
            var msg = "Showing how to add line break."
            msg += newLine;
            msg += "Line Break can be easily added in JavaScript.";
            msg += newLine;
            msg += "Simply Easy Learning";
            msg+= newLine;
            msg += "TutorialsPoint.com";
            alert(msg);
         }
      </script>
      <input type = "button" value = "Click" onclick = "DisplayAlert()" />
   </body>
</html>
raja
Published on 09-Jan-2018 09:45:59
Advertisements