Creating a callback function containing if else statement

- 1 answer

Ad

the problem I have is that I would like to use an if else statement in a callback function like this:

alertNotify("alert","Do you want to delete this",function(delete) {
   if(delete) {
      //do code
   }else {
      //do nothing
   }
});

current function code:

    function alertNotify(text,type) {
    $("body").append("<div id = 'alert' class='common'>\
                        <div id ='content'class='common'>\
                        </div>\
                      </div>");
    var alert = $("<div id = 'ok' class='common'>\
                     Ok\
                  </div>\
                  <div id = 'cancle''class='common'>\
                    Cancle\
                  </div>");
    var rename = $("<div class='common rename_it'>\
                      Ok\
                    </div>");
    var type_file = $("<input type='text' id ='rename'><div id='hover'></div>");
    if(type == "alert") {
        $("#content").append(text);
        $("#content").append(alert);
    }
    if(type == "rename") {
        $("#content").append(rename);
        $("#content").append(type_file);
    }
    $("#ok").click(function() {
        $("div").remove("#alert");
    });
    $(".rename_it").click(function() {
        $("div").remove("#alert");
    });
    $("#cancle").click(function() {
        $("div").remove("#alert");
    });

}

I would like the if statement to differentiate between whether the #ok div was clicked or the #cancel div was clicked but I have no idea where to start. Any ideas?

Ad

Answer

Ad

Sorry about that little bit of confusion. If I had of explained myself properly someone else might have answered but instead i got it. Add paremeter called callback and simply return callback(true); when the ok button is clicked and then my USB stopped working....

Ad
source: stackoverflow.com
Ad