Mottie
Mottie

Reputation: 86403

Disable a function

I have a tooltip that I want to disable. It is from this site and is basically set and called as follows:

this.tooltip = function(){....}
$(document).ready(function(){
 tooltip();
});

I don't want to unbind the hover or mouseover events since they are also tied to other effects. I have tried to disable without success as follows (at the bottom of the page):

 $(document).ready(function(){
  this.tooltip = function() {}
 })

and

 $(document).ready(function(){
  function tooltip() {}
 })

Am I missing something?

Upvotes: 0

Views: 9476

Answers (3)

prodigitalson
prodigitalson

Reputation: 60413

EDIT: Heres a thought... try taking your override out of the ready statement. That way it should override the function definition before onReady is ever fired.

this.tooltip = function(){return false;};

That wont work because the script calls itself in an external file, thus if you try to make it a blank function before hand then it overrides it, and if you do it afterwards it has already run, so while you override it it has already added its event handlers to the stack. You could jsut not include the file on the pages where you dont want the tooltips.

An easy way to handle this is to make the event handlers named functions instead of anonymous, then you can easily unbine only those functions from the event stacks with $('a.tooltip').unbind('click', tooltipClick); Ofcourse the more thorough way is to refactor it in to your own plugin with remove option or something of that nature. Also there are several tooltip plugins for jQ out there and im sure at least one, if not all will allow for disabling.

Upvotes: 1

Mottie
Mottie

Reputation: 86403

Ok, I was able to do it with this function. But it seems kind of hackish and may not be the most elegant solution.

$(document).ready(function() {
 $(".tooltip").mouseover(function(){ $('#tooltip').remove() });
});

I'll keep this question open in case any better ideas show up.

Upvotes: 0

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195972

You do not need to unbind the tooltip function (since its purpose is only to run once) but the anonymous functions that it adds to the events of some elements..

There is a way to do it, only if you can alter the original tooltip code to include a namespace when binding the anonymous functions..

some examples..

in the tooltip source code there is

$("a.tooltip").hover(function(e){...})

this should be

$("a.tooltip").bind('hover.tooltip',(function(e){...});

the .tooltip next to hover means that we have defined a namespace for this function and we can now unbind it with

$("a.tooltip").unbind('hover.tooltip');

Upvotes: 0

Related Questions