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?
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?
Share Improve this question edited Jun 16, 2011 at 14:11 DanielB 20.2k2 gold badges46 silver badges52 bronze badges asked Jun 16, 2011 at 14:08 user695663user695663 12.4k8 gold badges27 silver badges32 bronze badges 1- see this answer stackoverflow./questions/1432111/… – Bala R Commented Jun 16, 2011 at 14:12
1 Answer
Reset to default 10You can provide a callback function to the show
function, which will be executed upon pletion of show
:
$("#secondDiv").show(function() {
//Do something
});
As mentioned in the ments, 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.