JavaScript alert() Method
JavaScript alert() Method
The alert()
method displays an alert dialog with a specified message and an OK button.
Note: The alert dialog should be used for messages which do not require any response on the part of the user, other than the acknowledgement of the message.
alert() as HTML Attribute Value
Example
Syntax
Parameter Values
Value | Type | Explanation |
---|---|---|
message | Optional | Specifies the text/number to display in the alert box. Message can either be in string or number. |
Browser Support
All are checked by myself
alert() | ||
---|---|---|
yes | yes | |
yes | yes | |
yes | yes | |
yes | yes | |
yes | yes | |
- | yes | |
- | yes |
alert() inside <script> tag
Example
alert() with Escape Sequence
In the following example, we will use the escape sequence '\n' (new line) to display the following text in new line.
Example
alert() with Property
In the following example, we will using the location.hostname property to display the hostname.
Example
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.