How to Add New line in JavaScript Alert Box?
Add New line in JavaScript? – Javascript is a very widely used programming because of its easy and simplicity.
In website development, we will be met with a condition to display alerts that contain messages.
Alert Javascript by default will display text in one line only. If the text that we display is a lot, it will display writing that is not comfortable to look at.
From such conditions we must use New Line or “Enter” mode to make a new writing to the bottom line As shown below:
The command is “\n”. Yes, it is very simple code.
Example Program Code
For example is the following code:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display an alert box.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
alert("ip: 139.28.219.138\nversion: IPv4\ncity: Paris\nregion: Île-de-France\nregion_code: IDF\ncountry: FR\ncountry_name: France\ncountry_code: FR\ncountry_code_iso3: FRA\ncountry_capital: Paris\ncountry_tld: .fr\ncontinent_code: EU\nin_eu: true\npostal: 93200\nlatitude: 48.9335\nlongitude: 2.3661\ntimezone: Europe/Paris\nutc_offset: +0200\ncountry_calling_code: +33\ncurrency: EUR\ncurrency_name: Euro\nlanguages: fr-FR,frp,br,co,ca,eu,oc\ncountry_area: 547030.0\ncountry_population: 66987244.0\nasn: AS9009\norg: M247 Ltd");
}
</script>
</body>
</html>
Run the above program code in your browser, then click the Try button.
You will see neater data using New Line. If this article is useful, please share it with your friends using the share button below this article.