jQuery Add Line Breaks in Alert Message Box for New Line

Last Updated on November 7, 2020 by Roshan Parihar

In this tutorial, learn how to add line breaks in alert message box for new line in text using jQuery. The short answer is: use the jQuery \n symbol in the content of alert() to create your own jQuery alert box with line breaks in text messages. Add new line in jQuery alerts with the answer given here in the example below.

jQuery alert message box is the simple way of showing notifications to the user when they perform some actions. This is the simple way still using by many developers and coders to design a code and show errors or notifications in the alert message box.

jQuery Add Line Breaks in Alert Message Box for New Line

To create an alert with line break, you have to use the symbol \n inside the alert content where you want to put the line breaks or next line in alert. If you don’t know how to create alert message box, you can learn our tutorial on creating jQuery alert message box.

Below is a simple example that contains the jQuery alert function with simple text content. You can add line breaks in alert message box using the \n symbol inside the alert message box. It creates a next line in alert box using jQuery.

Output



Click the above button to see the alert message with the line breaks or next line in alert. Here, you can see there are only one line breaks in the alert message box.

You can add as many line breaks as you want using the \n symbol. Also add alert message on click of any HTML element using the id of the HTML element.

You May Also Like to Read