New Line Literal in JavaScript Alert Box

Mar 4, 2015 By Mohammed Imtiyaz




This tutorial will explain you how to use Newline Literal in JavaScript Alert Box

New Line Literal "\n" and Carriage Return Literal "\r" are used to display text in new line.


<input id="btnHtml" type="button" value="HTML Button" onclick="alert('HTML: \r\n\nFirst Line \r\nSecond Line')" />

Aspx Page

<asp:Button ID="btnAspnet" runat="server" Text=" Button" OnClientClick="alert(' \r\n\nFirst Line \r\nSecond Line')" />

NOTE: You can add as many new line literals as you want, simply by adding "New Line Literal, \n" as mentioned below:

alert('First Line \r\n\nSecond Line')