New Line Literal in JavaScript Alert Box

Mar 4, 2015 By Mohammed Imtiyaz

Demo

Demo

Introduction

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.

Html

<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="Asp.net Button" OnClientClick="alert('Asp.net: \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')



Post your comment