tipTip works on 'second' hover after ajax request using tiptip and jquery on()

杀马特。学长 韩版系。学妹 提交于 2019-12-24 13:53:04

问题


I'm using wordpress + ajax calendar future post plugin ( http://wordpress.org/extend/plugins/wordpress-plugin-ajax-calendar-with-future-posts/ ) + tiptip plugins http://code.drewwilson.com/entry/tiptip-jquery-plugin. I've managed to get them working together, though the tiptip only works on the 2nd hover - What I mean is when you first time hover element after ajax request tiptip doesn't show. I use the calendar as a widget on my home page.

This is the way I activate tiptip.

jQuery(document).ready(function( $ ) {

    $("#wp-calendar").on("hover"," td a", function(){ $(this).tipTip(); });
...
});

it works fine for the initial load if I use

$("#wp-calendar td a").tipTip();

, but it disappears after ajax request.

The question is how do I get the tiptip to show the way it supposed to show: on the 'first hover', mouseenter, mouseover etc. I've tried all of those events. AKA: How do I get the first piece of code to work properly.

I've tried to find an answer, which got me to the stage I'm now. It's beyond my 'now-skill' to get pass this.


回答1:


Well i think that if you make an AJAX call you and recreate the elemenets you must re-initialize the plugin. I think you should put this call

 $("#wp-calendar td a").tipTip();

in the success handler of the ajax call AFTER the new elements have been inserted. If you can't control the ajax call try using ajaxComplete()

$('body').ajaxComplete(function(e, xhr, settings){
     $("#wp-calendar td a").tipTip();
});

If you do this, i think you can take away this call:

$("#wp-calendar").on("hover"," td a", function(){ $(this).tipTip(); });

because you already have reapplied the plugin.



来源:https://stackoverflow.com/questions/8386176/tiptip-works-on-second-hover-after-ajax-request-using-tiptip-and-jquery-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!