any method like onshow() for a div
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.
精彩评论