jQuery cluetip('destroy') does not destroy/remove cluetip?

本秂侑毒 提交于 2019-11-28 09:06:35

问题


I'm trying to make sense of how cluetip actually works. I have a dummy DOM structure which I did some alerts on to check if the cluetip has been removed after the cluetip('destroy') was called on the anchor element. However, the cluetip div still appears to be alive and well. This really confuses me...

Correct me if I'm wrong... AFAIK, cluetip has 1 instance in the webpage, and it exists in a hierarchy of tags, i.e. cluetip > cluetip-outer > cluetip-inner. It appends itself somewhere to the DOM structure when it is first appended to a html element (in my case, an anchor).

So the question: would calling cluetip('destroy') on the html element actually remove the cluetip, or would it remove/reset some sort of variable in the cluetip (and if so, which variable)? Or am I totally off the track here?

Thanks.


回答1:


It looks like all the destroy function does is remove the event trigger (lines 28-30)

if (js == 'destroy') {
  return this.unbind('.cluetip');
}

If you want to ensure the data in the cluetip is gone, then clear it yourself:

$('#cluetip-inner').empty();

Update: To answer your question about seeing if an element has anything bound to it, I'll refer you to something I found from James Padolsey's site:

// List bound events:
console.dir( jQuery('#elem').data('events') );

// Log ALL handlers for ALL events:
jQuery.each($('#elem').data('events'), function(i, event){
    jQuery.each(event, function(i, handler){
        console.log( handler.toString() );
    });
});

*Note: the console is referring to the Firebug console.




回答2:


Try the following:

$(this).cluetip('destroy'); 
$(this).remove(); 

The remove() function should also unbind the events.



来源:https://stackoverflow.com/questions/1950197/jquery-cluetipdestroy-does-not-destroy-remove-cluetip

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