You can use JavaScript alert messages to display some information displaying blocks to the user interacting with your web pages. For example, onclick of button you can add a JavaScript alert message.
JavaScript Code Example
<input
id="btnClick"
type="button"
value="click me"
onclick="alert('Hello World');" />
You can use the above code to popup the alert message on the click event of the button
alert('Hello World');
Alert function also accepts the string values that can be displayed on any event triggered.
You can also display the multi line messages in the JavaScript alert messages. Just use back slash n (\n) to insert the new line in the string.
<input
id="btnClick"
type="button"
value="click me"
onclick="alert('Hello World!!!\nWhats Up?')" />
It will display the multi line message box alert.
You can use function also to call the JavaScript alerts.
Continue to next tutorial: JavaScript Confirm Box to learn how to open the confirm message box using JavaScript.