Skip to content

JavaScript alert Yes No | jQuery confirm dialog yes no Example

  • by

The Alert dialog box stops the whole process until the user gets a mouse response on its buttons. To Show, the custom alert box you have to use a library like – You can use jQuery UI Dialog. In the tutorial, you will learn how to create a JavaScript alert Yes No button option.

JavaScript alert Yes No

Before start you must read this tutorial to know about JavaScript alerts – JavaScript Alert Hello World | Alert box.

Javascript confirm Yes No Alert Dialog example

You can’t do that with the native confirm() as it is the browser’s method.

You have to create a plugin for a confirm box (or try one created by someone else). And they often look better, too.

Jquery libraries create HTML elements that look and behave like a dialog. You can put anything you want (including form elements or video or images) in the dialog.

Here is example code for it:-

<!DOCTYPE html>
        <script src=""></script>
            function functionConfirm(msg, myYes, myNo) {
                var confirmBox = $("#confirm");
                confirmBox.find(".yes,.no").unbind().click(function() {
            #confirm {
                display: none;
                background-color: #f2f4ef;
                border: 1px solid #aaa;
                position: fixed;
                width: 250px;
                height: 150px;
                left: 50%;
                margin-left: -100px;
                padding: 8px;
                box-sizing: border-box;
                text-align: center;
        #confirm button {
            background-color: #4aace3;
            display: inline-block;
            border-radius: 5px;
            border: 1px solid #aaa;
            padding: 5px;
            text-align: center;
            width: 80px;
            cursor: pointer;
            margin-top: 20px;
        #confirm .message {
            text-align: left;
        <div id="confirm">
            <div class="message"></div>
            <button class="yes">Yes</button>
            <button class="no">No</button>
        <button onclick = 'functionConfirm("Do you like Cricket?", function yes() {
            function no() {


Javascript confirm Yes No Alert Dialog example


Q: How to create a dialog with a “yes” and “no” button in JavaScript?

Answer: You can create a dialog box with a “Yes” or “No” button option or any custom color and style. To create an Alert dialog with “Yes” or “No”, use a custom dialog box.

Do comment if you have any doubts and suggestions on this tutorial.

Note: The jquery confirm dialog yes no Examples are tested on Safari browser (Version 12.0.2).
OS: macOS 10.14 Mojave
Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *