onHide() type event in jQuery

Sam picture Sam · May 18, 2010 · Viewed 96.4k times · Source

Does anyone know of an onHide() event or something similar in jQuery?

I tried:

$(this).bind('hide', function(){
    console.log('asdasda')
})

But apparently that doesn't work.

Edit: Just to clarify, it's being hidden using CSS display:none.
I'm aware of the callback function but as I'm not hiding it (the CSS is) I can't use it. For what it's worth, I need to check when a dropdown is visible. It's being shown by the following CSS:

ul li:hover ul {
    display: block;
} 

Answer

PetersenDidIt picture PetersenDidIt · May 18, 2010

There isn't a native or built in "hide" event but if you are using jQuery to hide it you can easily add a hide event:

var _oldhide = $.fn.hide;
$.fn.hide = function(speed, callback) {
    $(this).trigger('hide');
    return _oldhide.apply(this,arguments);
}