The alert()
method displays an alert box with a specified message and an OK button.
alert |
Yes | Yes | Yes | Yes | Yes |
alert(message)
Parameter | Description |
---|---|
message | Optional. Specifies the text to display in the alert box |
No return value.
The following code shows how to display an alert box.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w w w.j a v a 2 s. co m-->
alert("Hello! I am an alert box!");
}
</script>
</body>
</html>
The code above is rendered as follows: