admin管理员组

文章数量:1336563

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

Is there an evert handler that is fired when I hide something? You see, I have a bunch of elements in my code, and I'm hiding them or showing them (using jQuery) a bunch of times. To keep things in check, in an efficient way, I would love to use an event handler for .hide()

Could someone point me in the right direction for this?

Many Thanks!

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

Is there an evert handler that is fired when I hide something? You see, I have a bunch of elements in my code, and I'm hiding them or showing them (using jQuery) a bunch of times. To keep things in check, in an efficient way, I would love to use an event handler for .hide()

Could someone point me in the right direction for this?

Many Thanks!

Share edited Mar 30, 2012 at 1:48 Greg Pettit 10.8k5 gold badges57 silver badges73 bronze badges asked Mar 30, 2012 at 1:15 Umm....Umm.... 792 silver badges7 bronze badges 2
  • 1 You can provide a callback for hide() if you want, but I don't think this is what you are looking for. Can you please explain what you are trying to achieve? – Niyaz Commented Mar 30, 2012 at 1:19
  • There is no onhide event, its a custom method from jQuery which uses animations to create a "hiding" effect on the element. – mowwwalker Commented Mar 30, 2012 at 1:24
Add a ment  | 

3 Answers 3

Reset to default 4

You can use a 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
}
$('p').on('ohWowIGotHidden', function(){
    document.write('O look, it works');
});

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

​You can create a custom event and trigger it whenever you call the hide method..

You can override hide in jquery to dispatch an event after calling the original function.

本文标签: javascriptjQuery onhide event handlerStack Overflow