Alternatively, you can opt to not load an entire Javascript library for something as simple as this:

document.querySelector('#button').addEventListener('onclick', exit_alert);
Answer from anon on Stack Overflow
🌐
W3Schools
w3schools.com › js › tryit.asp
W3Schools Tryit Editor - JavaScript Alert
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
TutorialsPoint
tutorialspoint.com › javascript-create-an-alert-on-clicking-an-html-button
JavaScript - Create an alert on clicking an HTML button
March 11, 2025 - <!DOCTYPE html> <html lang="en"> ... pressedButton = document.getElementsByTagName("button")[0]; pressedButton.addEventListener("click", function (event) { alert("You have pressed the button..........") }) </script> </html> ... Whenever you press the button, you will get an alert ...
🌐
IncludeHelp
includehelp.com › code-snippets › display-alert-message-on-button-click-event.aspx
Display Alert Message on Button Click Event using JavaScript
HTML and JavaScript: <!--Display ... Click Event.</h1> <b>Click on button to display message: </b><br /> <br /> <input type="button" id="btnShowMsg" value="Click Me!" onClick="showMessage()" /> </center> </body> </html> Result: Click for DEMO → ·...
🌐
Codecademy
codecademy.com › forum_questions › 512d28a06918338f2300e9ea
How to make a html button clickable and to show alert on it ? | Codecademy
<script> function clickAlert() { alert("Alert!"); } </script> <input type="button" onclick="clickAlert()" value="Click-2-Alert">
🌐
W3Schools
w3schools.com › howto › howto_js_alert.asp
How To Create an Alert Message Box
If you want the ability to close the alert message, add a <span> element with an onclick attribute that says "when you click on me, hide my parent element" - which is the container <div> (class="alert"). Tip: Use the HTML entity "&times;" to ...
🌐
University of Washington
washington.edu › accesscomputing › webd2 › student › unit5 › module2 › lesson1.html
Lesson 1: Using JavaScript to Show an Alert
The onclick event also works for keyboard users. If a user navigates to the button using the tab key, then presses enter, that too will trigger the alert. After you have added the button, add a new <style> element to the head section of your page, and add a new style for the button element.
🌐
SheCodes
shecodes.io › athena › 40000-how-to-create-a-button-with-click-alert-in-javascript
[JavaScript] - How to create a button with click alert in | SheCodes
Learn how to create a button in HTML and add a click event listener in JavaScript to show an alert message ... if I have a variable outside a function, do I need to redefine that variable inside the function? similarly, can use the same name for a variable if one is in a function?
Find elsewhere
🌐
CodePel
codepel.com › home › html & css › alert message in html on button click
Alert Message in HTML on Button Click — CodePel
January 27, 2024 - Here is a free Alert Message in HTML on Button Click , source code with preview. You can view demo online & download code.
Address   Rafi Qamar Road, Al-Majeed Peradise Al Majeed Peradise, 62300, Bahawalpur
🌐
Indiana
info.sice.indiana.edu › ~hrosenba › Demo › javascript › 6alert.html
Alert and Confirm
This is how the script would look: It is important to note the placement of quotation marks in these examples. In the examples where the code is triggered by a button click, the entire code must by contained in quotation marks: onClick="alert( 'Your Message Here...'
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › javascript onclick alert
JavaScript onclick Alert | How does JavaScript onclick Alert work?
October 18, 2022 - In the above examples we will use the onclick and alert events are used in the web pages with different scenarios first example we use the normal onclick and alert events are triggered in the same web page whenever the user click the html tag elements like button in second example we use one more additional event like addEventListener() is one of the event and this event is handled by its own listener so whenever the clicks the button this event is triggered and called the JavaScript functions even we can’t enter any values in the text box it shows alert message.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-set-alert-message-on-button-click-in-jquery
How to set alert message on button click in jQuery ? | GeeksforGeeks
September 23, 2024 - Example: In this example we use jQuery to trigger an alert message when a button is clicked. The click() event on the button displays the alert message: "This is an alert message!" when clicked. HTML ·
🌐
GeeksforGeeks
geeksforgeeks.org › html › html-dom-window-alert-method
HTML DOM Window alert() Method - GeeksforGeeks
In this example the alert() is used to display a message box when the button is double-clicked. The message informs users about GeeksforGeeks. It's a simple way to show notifications or information.
Published   August 16, 2021
🌐
Stack Overflow
stackoverflow.com › questions › 66790588 › alert-message-on-button-submit-javascript
html - alert message on button submit javascript - Stack Overflow
function myFunction() { alert("message successfully sent").then(response => { window.location.href = 'index.html'; }) } <div class="col-lg-12"> <input type="submit" class="btn btn-defeault btn-send" value="Send message" onclick="myFunction()"> ...
🌐
Codeconvey
codeconvey.com › home › display message on button click in html
Display Message on Button Click in HTML | Codeconvey
August 28, 2023 - In this tutorial, you will learn how to display a message box on button click in HTML, CSS & JS. You can also download code for messgae box.
🌐
Bootstrap
getbootstrap.com › docs › 4.0 › components › alerts
Alerts · Bootstrap
Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages. Alerts are available for any length of text, as well as an optional dismiss button. For proper styling, use one of the eight required contextual classes (e.g., .alert-success).
🌐
W3Schools
w3schools.com › howto › howto_css_alert_buttons.asp
How To Create Alert Buttons
Create a Website Make a Website Make a Static Website Host a Static Website Make a Website (W3.CSS) Make a Website (BS3) Make a Website (BS4) Make a Website (BS5) Create and View a Website Create a Link Tree Website Create a Portfolio Create a Resume Make a Restaurant Website Make a Business Website Make a WebBook Center Website Contact Section About Page Big Header Example Website · 2 Column Layout 3 Column Layout 4 Column Layout Expanding Grid List Grid View Mixed Column Layout Column Cards Zig Zag Layout Blog Layout · Google Charts Google Fonts Google Font Pairings Google Set up Analytics · Convert Weight Convert Temperature Convert Length Convert Speed · Get a Developer Job Become a Front-End Dev. Hire Developers ... Learn how to style "alert" buttons with CSS.
🌐
The HTML Shark
html-shark.com › JavaScripts › PopupBox.htm
Popup boxes using alert(), confirm() and prompt() | The HTML Shark
February 19, 2026 - If Cancel is clicked, you write an empty string, "", as you need the script to react to the click, otherwise you get an error message. Then the code looks like this: <BUTTON TYPE="button" ONCLICK="promptFunction()">Click me!</BUTTON> <SCRIPT> function promptFunction() { var Text = prompt("Write ...