最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - any method like onshow() for a div - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 10

You 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.

发布评论

评论列表(0)

  1. 暂无评论