I have a div that is shown or hidden dynamically. I want some function to execute when the div is shown for the first time. Let me know how to do that.
<div id="firstDiv"></div>
<div id="secondDiv"></div>
so when $('#secondDiv").show();
I want to perform some function.
How I can do that?
You can provide a callback function to the
showfunction, which will be executed upon completion ofshow:As mentioned in the comments, this will behave as an animation. If you want
showto behave as normal (i.e. the element appears instantly with no animation) you need to supply a duration parameter of 0 to theshowfunction. The difference is demonstrated in this fiddle.