How to set alert message on button click in jQuery ? Last Updated : 23 Sep, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Setting an alert message on a button click in jQuery means using jQuery to capture the button's click event and trigger a browser alert box. This alert displays a custom message to the user whenever the button is clicked.jQuery CDN Link: We have linked the jQuery in our file using the CDN link. <script src="https://code.jquery.com/jquery-3.6.0.min.js" crossorigin="anonymous";> </script>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 <!DOCTYPE html> <html lang="en"> <head> <script src= "https://code.jquery.com/jquery-3.6.0.min.js" integrity= "sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"> </script> </head> <body> <button id="btn">Click me!</button> <script> $(document).ready(function () { $("#btn").click(function () { alert("This is an alert message!"); }); }); </script> </body> </html> Output:Alert msg using click method Comment More infoAdvertise with us Next Article How to set alert message on button click in jQuery ? I iamgaurav Follow Improve Article Tags : Web Technologies JQuery jQuery-Methods jQuery-Questions Similar Reads How to hide/show an image on button click using jQuery ? In this article, we will see how we can hide or show any particular image in jQuery when a button gets clicked. This is quite easy to do with some lines of jQuery code. Before we jump to the topic, let's know which methods of jQuery will be used for this. So there is a method called show() and anoth 3 min read How to use hide() method on button click using jQuery ? jQuery has a lot of handy methods to get the work done easily. In this article, we will discuss one of them which is the hide() method. We can use this method for various purposes on our webpage and get an efficient result. The very first step will be creating an HTML file and link the jQuery librar 2 min read How to Make a Simple jQuery AJAX Call on Link Click? To make a simple jQuery AJAX call when a link is clicked, you can use jQuery's .click() method and the $.ajax() function to send a request and handle the response. Here's a basic example to demonstrate how this works:Example: jQuery AJAX Call on Link ClickHTML Structure:HTML<a href="#" id="myLink 2 min read How to create an Alert icon using jQuery Mobile? jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be making an Alert icon using jQuery Mobile. Approach: First, add jQuery Mobile scripts needed for your project. <link rel=âstylesheetâ 1 min read How to run a code on click event in jQuery ? In this article, we will see how to run the code after clicking on an event. To run the code after clicking an event, we use the click() method. The click() method is used to run the code when a click event occurs. The click() method to attach a click event handler to selected elements. Inside the h 1 min read Like