IsFunction () is always false in jQuery

so I use qtip to implement a super simple tool.

I do not include qtip on every page, only the pages that you need, so I am trying to verify the existence of qtip before calling it.

/* * Tool Tip * inits qtip on any link with class="tt" */ if( $.isFunction( $.qtip ) ){ $(".tt").qtip(); } 

I have no idea this is not working. it always returns false. Any ideas? thanks.

+4
source share
6 answers

IMO you have to check

 if($.isFunction($.fn.qtip)) 
+11
source

try the following:

 if( $.isFunction( $.fn.qtip ) ){ $(".tt").qtip(); } 

since plugins are in the $.fn object

+1
source

I prefer to use the typof operator since it is not dependent on jQuery.

 if(typeof window.myFunction == 'function') { // function exists, so we can now call it myFunction(); } 

On the side, a note is a great way to β€œextend” javascript to β€œIf” something exists (e.g. form validation)

+1
source

If the implementation is consistent across all your pages, just put

 $(function(){ $(".tt").qtip(); } 

at the bottom of the qtip.js file, it runs when qtip is enabled.

0
source
 if( $.isFunction(qtip) ){ //bla bla } 

try this or with commas

 if( $.isFunction("qtip") ){ //bla bla } 
0
source

Try to remove the "$". before qtip in checking isFunction.

0
source

Source: https://habr.com/ru/post/1300680/


All Articles