JQuery onhide event handler

In jQuery, I hide my elements using .hide();

.

Is there an evert handler that gets triggered when I hide something? You see, I have a bunch of elements in my code and I hide or show them (using jQuery) a bunch of times. To keep things in check, in an efficient way, I would like to use an event handler for.hide()

Can anyone point me in the right direction?

Many thanks!

+3


source to share


3 answers


You can use the callback function



$('#element').hide('slow', hideCallback);

$('#element').show('slow', showCallback);

function hideCallback()
{
    // You can do your stuff here
}

function showCallback()
{
    // You can do your stuff here
}

      

+4


source


$('p').on('ohWowIGotHidden', function(){
    document.write('O look, it works');
});

$('p').hide(function(){
    $(this).trigger('ohWowIGotHidden');
});

      



You can create a custom event and call it when you call the hide method.

+2


source


You can override hide in jquery to dispatch the event after the original function is called.

+1


source







All Articles