JQuery dialog how to set click event?

Ok, I got this code:

    $(document).ready(
    function() {
        $(".dialogDiv").dialog({
            autoOpen: false,
            modal: true,
            position: [50, 50],
            buttons: {
                "Print page": function() {
                    alert("Print");
                },
                "Cancel": function() {
                    $(this).dialog("close");
                }
            }
        }
        );
    $('.ui-dialog-buttonpane button:contains("Print page")').attr("id", "dialog_print-button");
    $(".dialogDiv").parent().appendTo($('form'));
    }

How to assign or install a new function for a click event?

$ ("# dialog_print button"). ???

Edit, this works:

$("#dialog_print-button").unbind("click").click(
function () {
   alert("new function that overide the old ones")
}
)

Tried to find how to do this in the jQuery documentation, but I find it hard to find it in the documentation. Especially when new to javaScript and jQuery libary.

Change, a quick way to get help is to go to the jQuery irc: D channel

+5
source share
4 answers
$("#Print page").click(function () {
   ...
});

Or maybe it should be

$("#dialog_print-button").click(function () {
   ...
});
+5
source

I think this would help:

$(".dialogDiv").dialog("option", "buttons", {
    "Print page": function() { /* new action */ },
    "Cancel": function() { $(this).dialog("close"); }
});

buttons , cancel.

+7

jQuery UI "id".

    $("#dialog-form").dialog({
        autoOpen: false,
        height: "auto",
        width: 300,
        buttons:
        [
            {
                text: "Create Revision",
                id: "btnCreateRev",
                click: function () {
                    //code for creating a revision
                }
            },
            {
                text: "Cancel",
                id: "btnCancel",
                click: function () { $(this).dialog("close"); },
            }
        ]
    });
+4
source

You put the code in the button section:

 ...
 buttons: {                   
         "Print page": function() {                       
          //here you execute the code or call external functions as needed 
          }

As soon as you click the button in the dialog box, this code will be automatically called. Therefore, you insert code there that implements your logic.

+1
source

All Articles