开发者

isFunction() always false in jQuery

开发者 https://www.devze.com 2022-12-19 08:27 出处:网络
so I\'m using qtip for a super simple tool tip implementation. I\'m not including qtip on every page, only the pages that needed, so I\'m trying to check for qtip\'s existence before calling it.

so I'm using qtip for a super simple tool tip implementation.

I'm not including qtip on every page, only the pages that needed, so I'm trying to check for qtip's existence before calling it.

 /*
  * Tool Tip
  * inits qtip 开发者_C百科on any link with class="tt"
  */
  if( $.isFunction( $.qtip ) ){
  $(".tt").qtip();
  }

I've no idea what this isn't working. it's always returning false. Any ideas? Thx.


IMO, you should check

if($.isFunction($.fn.qtip))


try this:

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

as plugins reside in the $.fn object


I prefer using the typof operator since it's not jQuery dependent.

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

On a side note it's a great way to "extend" javascript on "If" something exists (like form validation)


If the implementation is consistent accross all you your pages, then just put

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

at the bottom of the qtip.js file, that way, it is executed whenever qtip is included.


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

try this or with commas

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


Try removing the "$." before the qtip in the isFunction check.

0

精彩评论

暂无评论...
验证码 换一张
取 消