views:

89

answers:

1
$(document).ready(function(){
$('#rest').colorbox();
$("#cboxClose").click(function(){ $.fn.colorbox.close(); });
var cboxClose = $.fn.colorbox.close;
$.fn.colorbox.close = function(){ if(confirm("Are you sure?")) { cboxClose(); } }
});

this code close my jquery colorbox when i confirm the dialog, but if i click on cancel (!confirm) its as closing

what im doing wrong?

A: 

I think this can be done a little simpler

$(function(){

    $('#rest').colorbox();

      // If close button is clicked...
    $("#cboxClose").click(function(){ 

          // Confirm desire to close, and only close if confirmed
        if(confirm("Are you sure?")){ $.colorbox.close(); };
    });

});

Note:
$(function() { ... }); is synonymous with $(document).ready(function() { ... });

Peter Ajtai