Skip to content
Related Articles

Related Articles

How to set alert message on button click in jQuery ?

Improve Article
Save Article
  • Last Updated : 28 Jul, 2021
Improve Article
Save Article

In this article, we will learn how to create an alert message in jQuery when a button gets clicked. For this, we will use the jQuery click() method.

jQuery CDN Link: We have linked the jQuery in our file using the CDN link. 

<script src=”” integrity=”sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=” crossorigin=”anonymous”;>

Example: Create a new HTML file and add the following code to it. In this method, we have set an alert and linked it to a button so that when that button gets clicked then the alert message will be popping out.


<!DOCTYPE html>
<html lang="en">
    <script src=
    <button id="btn">Click me!</button>
        $(document).ready(function () {
            $("#btn").click(function () {
                alert("This is an alert message!");


Alert msg using click method

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!