238 of 264 menu

alert function

The function alert shows a modal box with a given message. The site user will not be able to continue working until he/she clicks on the OK button. Only text will be displayed, tags in the modal box will be ignored.

Syntax

alert(message);

Example

Let's make it so that when the button is clicked, a modal box appears with a message:

<button id="button">click me</button> let button = document.querySelector('#button'); button.addEventListener('click', function(event) { alert('abcde'); });

:

See also

  • the confirm function
    that brings up a confirmation dialog box
  • the prompt function
    that brings up a dialog box with a question
byenru