jQuery live with the ready or load event

后端 未结 3 1012
孤街浪徒
孤街浪徒 2020-12-20 17:19

I\'m using the jQuery Tools tooltip plugin, which is initialized with $(\'selector\').tooltip(). I\'d like to call this on any current or future .tooltipp

3条回答
  •  青春惊慌失措
    2020-12-20 17:37

    HurnsMobile is right. JQuery live does not support the ready-event.

    This is why I created a plugin that combines the two. You register your callback once, and then you will need to call the plugin once for content you add manually.

    $.liveReady('.tooltipper', function(){
      this.tooltip()
    });
    

    Then when creating new content:

    element.html(somehtml);
    element.liveReady();
    

    or

    $('
    ...').appendTo($('body')).liveReady();

    A demo is available here: http://cdn.bitbucket.org/larscorneliussen/jquery.liveready/downloads/demo.html

    Check out the introductory post here: http://startbigthinksmall.wordpress.com/2011/04/20/announcing-jquery-live-ready-1-0-release/


    Also have a look at http://docs.jquery.com/Plugins/livequery, which listenes for changes on the dom.

提交回复
热议问题