Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom jQuery event listener that triggers on show()

Tags:

jquery

I have a div that gets hidden and displayed, via .hide() and .show(). When it is displayed by .show() I need it to do some stuff. Is there any way I can setup a custom event listener that fires a callback when the div goes from hidden to visible? I can make a function and call it wherever I would call $(#myDiv").show() but that happens in multiple places and I would like to keep this all in one place.

like image 563
roflwaffle Avatar asked Dec 28 '22 01:12

roflwaffle


2 Answers

You can pass a function callback into the show method which will execute after the show has completed:

$("#myDiv").show(function(){
   myCustomFunction();
});
like image 174
Brian Flanagan Avatar answered Dec 30 '22 13:12

Brian Flanagan


You could use you own function instead of the internal "show" with a specific callback.

like image 34
Capsule Avatar answered Dec 30 '22 14:12

Capsule