javascriptjqueryalertify

pass 'this' to alertify


I want to use alertify.js after "finding" a button in a div with the class .removeRow

  $(".removeRow").find("button").click(function(){
            alertify.confirm("remove this field?", function (e) {
                if (e) {
                    // user clicked "ok"
                    $(this).closest(".agrRow").remove();
                }
            });     
  });

the problem is after I call alertify, I loose the value of "this". How can I pass "this" into the alertify function?


Solution

  • $(".removeRow").find("button").click(function(){
        var temp = this;
        alertify.confirm("remove this field?", function (e) {
            if (e) {
                // user clicked "ok"
                $(temp).closest(".agrRow").remove();
            }
        });     
    });