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 show
function, which will be executed upon completion of show
:
$("#secondDiv").show(function() {
//Do something
});
As mentioned in the comments, this will behave as an animation. If you want show
to behave as normal (i.e. the element appears instantly with no animation) you need to supply a duration parameter of 0 to the show
function. The difference is demonstrated in this fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With