Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: How to call function when element shows

Tags:

jquery

bind

show

I want to call a function when a div shows (after show).

Does anybody knows how could I do this? I try to use something like that:

$(#someDiv).bind('show',function(){
    alert('example')
});

But I don't sure if I do that from correct way or if it is possible or not achieve that. Any ideas?

like image 364
user1364684 Avatar asked Mar 05 '13 19:03

user1364684


1 Answers

The following code (adapted from http://maximeparmentier.com/2012/11/06/bind-show-hide-events-with-jquery/) will enable you to use $('#someDiv').on('show', someFunc);.

(function ($) {
  $.each(['show', 'hide'], function (i, ev) {
    var el = $.fn[ev];
    $.fn[ev] = function () {
      this.trigger(ev);
      el.apply(this, arguments);
      return el;
    };
  });
})(jQuery);
like image 72
JellicleCat Avatar answered Nov 15 '22 03:11

JellicleCat