简体   繁体   中英

Execute default event before custom click function

I'm trying to execute the default event of a button before executing my custom function

my code:

$('#Button').click( function (){
    sideMenuCheck();
});

I wan't this to be executed after the default event of the function Like this:

$('#Button').click( function (){
    **event.default();**
    sideMenuCheck();
}); 

but I didn't find any solution.


Not important

I'm doing this because I have an off-canvas menu, and menu has to be with the visible height after it opens, (#Button) is the button that opens menu from the side.

You can wrap up your code in a setTimeout with a timeout of 0 - this will cause it to move your code to the bottom of the execution queue, and allow everything else to run first:

$('#Button').click( function (){
    window.setTimeout(function() {
        sideMenuCheck();
    }, 0);
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM