Is it possible that I can call another event handler inside the event?

I have these two sets of codes, one of which should be displayed whenever a button is clicked,

$('.button_class').click(function(){
    var baker_url = base_url + 'baker/baker/manage/Bread/1';
    var answer = confirm('Are you sure?');
    if(answer == true){
        // if this is true, i will call an external script so that within this condition that process will be executed
    }
    else if(answer == false){
        return false; // exits
}
});

and then this piece of code here is the one that is responsible for executing the process when the button is clicked,

$('.another_button_class').click(function(e){
        e.preventDefault();
        var baker_url = base_url + 'baker/baker/manage/Bread/1';
        var form    = '#'+ $(this).attr('rel');
        var url     = $(form).attr('action');
        var target  = '#'+ $(form).attr('rel');
            $(target).slideUp();
            $.post(url, $(form).serialize(),function(data) {
                $(target).html(data).slideDown(function(){
                    if(data == '<div class="ok">Added</div>'){
                    setTimeout(refresh,1000)
                    c();
                    window.location = baker_url; // sets the url after refreshing
                    }
                });

            });
    });

in the first function, when answer == true, I want to execute the last function (the one with which the process is executed when the button is pressed).

Is it possible that I can call another function or event handler to execute my process inside another function?

+3
source share
2 answers

, , # 2, # 1 ? , :

  • , e - undefined; , , . .

  • 1: , , e.preventDefault(); . .

  • jQuery , 'yes'.

EDIT . , .

+2

,

if(answer == true){
    // if this is true, i will call an external script so that within this condition that process will be executed
    $('.another_button_class').trigger('click');
}

, $('.another_button_class').


e.preventDefault(); ,

+1

All Articles