开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜