简体   繁体   中英

jQuery UI Tooltip and AJAX, how to implement live() with it?

On certain pages I have code like $('.tooltip').tooltip(); . Example element would look like:

<a title="Tooltip content" class="tooltip" href="javascript:void(0);"><img src="icon.png" /></a>

This works beautifully unless I want to reload those elements with AJAX. Then, the tooltip handlers are not reattached to the new content and the tooltips do not work any more.

I have attempted to do a workarounds to somehow reattach the tooltip to the elements with no particular success. Any advice is appreciated!

You need to reinitialise tool-tip $('.tooltip').tooltip(); in your AJAX success callback

您只能通过以下方式为新添加的元素重新初始化工具提示:

$('.tooltip').not('.hasTooltip').tooltip().addClass('hasTooltip');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM