0

Is it possible to achieve formatting of text in JS alert message?

<script>
function myFunction() {
alert("1.Enter your name. 2. Enter your mobile no. 3.Do not press back 
button.");
}
</script>

I want these 3 messages to appear one below the other. I tried:

<p>1.Enter your name.</p><p> 2. Enter your mobile no.</p><p> 3.Do not
press back button.</p>

Didn't work. Also, wish to add this img src tag after the last message:

<img src="http://forums.nextgames.com/resources/emoji/smiley.png" alt="smily"/>

Thank you.

Chetan
  • 11
  • 1
  • 10
  • Duplicate to https://stackoverflow.com/questions/17470817/format-the-text-in-javascript-alert-box . You should consider using Bootstrap modals or jQuery UI – Vinko Vorih Aug 21 '17 at 05:10
  • Possible duplicate of [format the text in javascript alert box](https://stackoverflow.com/questions/17470817/format-the-text-in-javascript-alert-box) – Nisarg Shah Aug 21 '17 at 05:11

3 Answers3

1

The alert box is a object, and not related to CSS. To do this style of thing you would need to create an HTML element and mimic the alert() functionality. The jQuery UI Modal box does a lot of the work for you.

Ashish sah
  • 755
  • 9
  • 17
1

try adding "/n" before the lines example "\n2", "\n3"

Israr ahmad
  • 77
  • 1
  • 8
0

The browser alert box does not support rendering HTML, however you can use plain-text formatting like \n newline and \t tab.

alert("1.Enter your name.\n2. Enter your mobile no.\n3.Do not press back button.");
Marty
  • 39,033
  • 19
  • 93
  • 162