Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 369
user695663 Avatar asked Dec 27 '22 18:12

user695663


1 Answers

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.

like image 138
James Allardice Avatar answered Jan 09 '23 03:01

James Allardice