How to Change Button Label in Alert Box using JavaScript ? Last Updated : 16 Apr, 2024 Comments Improve Suggest changes Like Article Like Report In JavaScript, the alert method is used to display an alert box with a message. By default, the alert box contains an "OK" button. We cannot directly update the default alert box, However, we can customize the button label by creating a custom alert box using HTML, CSS, and JavaScript. ApproachCreate the UI of the web page using different HTML elements, and a stylish alert box using CSS.Define a hidden HTML div element for the custom alert box. This div will contain the message and the custom button.Use JavaScript to display the custom alert box when needed. Set the message and the button label dynamically.Attach an event listener to the custom button to handle its click event.Example: This example shows how we can implement this approach. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Custom Alert Box</title> <style> h1 { color: green; } body { text-align: center; } .custom-alert { display: none; position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%); background-color: #f8d7da; color: #721c24; padding: 10px; border: 1px solid #f5c6cb; border-radius: 5px; text-align: center; } </style> </head> <body> <h1>GeeksForGeeks</h1> <button onclick="showCustomAlert()">Show Custom Alert</button> <div id="customAlert" class="custom-alert"> <p id="alertMessage"></p> <button id="customButton">Close</button> </div> <script> function showCustomAlert() { const message = "This is a custom alert box!"; const buttonText = "Close me"; const alertBox = document.getElementById('customAlert'); const alertMessage = document.getElementById('alertMessage'); const customButton = document.getElementById('customButton'); // Set the message and button label alertMessage.innerText = message; customButton.innerText = buttonText; // Show the custom alert box alertBox.style.display = 'block'; // Handle button click customButton.addEventListener('click', function () { alertBox.style.display = 'none'; // Hide the alert box }); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Change Button Label in Alert Box using JavaScript ? yuvrajghule281 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to Change the Button Label when Clicked using JavaScript ? Changing the Label of the Button element when clicked in JavaScript can be used to provide more information to the user such as the text of the Submit button will change to the Submitted as soon as the form submission is completed. The below approaches can be used to accomplish this task: Table of C 2 min read How to Design a Custom Alert Box using JavaScript ? An alert box is a built-in feature in JavaScript that displays a small window with a message to the user. It's primarily used for providing information to the user, displaying warnings, or prompting the user for confirmation. The below approaches can be used to create a custom alert box in JavaScrip 4 min read 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 change the text of a label using JavaScript ? Changing the text of a label using JavaScript involves selecting the label element and updating its textContent or innerHTML property. This allows you to modify the displayed text dynamically, often in response to user interactions or changes in data, enhancing interactivity and responsiveness.Below 2 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 How to Style Alert Buttons using CSS? Styling alert buttons with CSS enhances user experience by making buttons more visually appealing and interactive. We can customize their look using CSS properties like color, padding, and hover effects. In this tutorial, we will focus on how to style "alert" buttons using CSS. These are the followi 5 min read How to Change Text Inside all HTML Tags using JavaScript ? In this article, we will learn how to change the text content inside all HTML tags using JavaScript. This skill is valuable when you need to dynamically modify the text displayed on a web page. which can be useful for various scenarios like updating content, internationalization, or creating dynamic 3 min read How to edit a JavaScript Alert Box Title in Bootstrap ? JavaScript alert boxes are an essential component, frequently used to deliver important messages or notifications to users. There are two methods to edit the title of a JavaScript alert box. First, you can create a custom modal dialog, offering complete control over appearance and functionality. Alt 3 min read Like