JavaScript Alert With & Without Line Breaks

 

Here the script uses the onclick event to trigger the "alert" give it a try!

 

Example

Alert without line break

 

Alert with line break

 

 

Source Code of Alert box without line break

 

 

<Under the head section>


<script type="text/javascript">
function alert_noline()
{
alert("This is the alert box without a line break!")
}
</script>

 

<Under the body section>

<input type="button" onclick="alert_noline()" value="Display alert box without line break!" />

 

Source Code of Alert box with line break

 

<Under the head section>.


<script type="text/javascript">
function alert_line()
{
alert("This is the alert box" + '\n' + "with a line break!")
}
</script>

 

<Under the body section>

<input type="button" onclick="alert_line()" value="Display alert box with line break!" />

 

Please let me know if this script was helpful to you.

[rating]