frenchie
frenchie

Reputation: 51937

jquery event handler: div becomes visible/hidden

I have a div and I'd like to have an event handler listen to when it becomes visible and hidden. How do you do that?

Thanks.

Upvotes: 14

Views: 33830

Answers (2)

Jason
Jason

Reputation: 52523

You can create a trigger. You would, of course, have to fire the trigger, but that is one way to do it.

Upvotes: 1

treeface
treeface

Reputation: 13341

You can use the callback parameter in the show() and hide() methods like this:

$('#myDiv').show(0, onDivShow);
$('#myDiv').hide(0, onDivHide);

function onDivShow() { //your code here }
function onDivHide() { //your code here }

See a working example here: http://jsfiddle.net/N7UNU/

Upvotes: 15

Related Questions