How to use the alert() method in JavaScript ? Last Updated : 23 Nov, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will learn how to use the alert() method in JavaScript. The alert() method is used to show an alert box on the browser window with some message or warning. We can use it as a message or as a warning for the user. Approach: To show an alert on the browser window, we make a button. When we click on the button, a click event listener is called that calls a function. In that function, we use the alert() method that contains a message for the user. When we click the button, the alert window will pop up on the browser window that contains a message or warning with a button. Then you have to click the OK button so that the alert box can be closed.Syntax:alert(message/warning);Below is the implementation of the above approach: Example: This example shows the use of the above-explained approach. HTML <!DOCTYPE html> <html lang="en"> <head> <style> body { /* path of the image */ background-image: url(gfg_complete_logo_2x-min.png); /* Image is always centered*/ background-position: center center; /* set the image fixed to the viewport */ background-attachment: fixed; /* Not repeat image */ background-repeat: no-repeat; /* Set background size auto */ background-size: auto; } </style> </head> <body> <div style="margin-left: 500px; margin-top: 300px;"> <button style="font-size: 20px;" class="btn" onclick="fun()"> click me </button> </div> <script> function fun() { alert("Welcome on gfg!"); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to use the alert() method in JavaScript ? S sachinchhipa44 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Methods Similar Reads How to show Image in an Alert Box using JavaScript ? Adding images in JavaScript alerts can make messages more eye-catching and easier to understand. It's a way to attract your attention and make the alerts more attractive. We will show the steps on how to put images in our JavaScript alerts and make your notifications clearer and more engaging for us 3 min read How to take user input in JavaScript? Interacting with users is the best way to create engaging and dynamic web applications. Taking user input allows your applications to be interactive and responsive. Here we will see the approach to take user input in JavaScript, specifically using the prompt method, which is perfect for beginners.Ap 3 min read How to Change the Color of the Alert Box in JavaScript ? An alert box is a dialogue box that pops up on the screen to provide information to the user. It contains a message and an OK button, which allow users to acknowledge the message and close the box. Alert boxes are commonly used in web development to display important messages, warnings, or notificat 5 min read How to Change the Color of the Alert Box in JavaScript ? Alert boxes, often utilized in JavaScript applications, provide users with important notifications or messages. However, their default appearance may not always blend seamlessly with the overall design of your website or application. JavaScript offers several methods to customize alert boxes as list 3 min read How to Create an Alert in JavaScript ? The alert() method in JavaScript displays an alert box with a message and an OK button. It's used when you want information to come through to the user, providing immediate notifications or prompts for user interaction during program execution. Note: Alert boxes interrupt user interaction, shifting 1 min read Like