JQuery custom event listener that runs show ()

I have a div that is hidden and displayed through .hide() and .show() . When it displays .show() , I need it to do some things. Is there a way to set up a custom event listener that calls the callback when the div changes from visible to hidden? I can make a function and call it wherever I call $(#myDiv").show() , but this happens in several places, and I would like to keep it all in one place.

+4
source share
2 answers

You can pass the function callback to the show method, which will be executed after the show ends:

 $("#myDiv").show(function(){ myCustomFunction(); }); 
+8
source

You can use your own function instead of the internal "show" with a specific callback.

+2
source

Source: https://habr.com/ru/post/1339039/


All Articles