JQuery and Colorbox loaded but “colorbox is not a function”

前端 未结 2 837
谎友^
谎友^ 2021-01-23 00:51

I have checked to see if both jQuery is loaded and the colorbox script is loaded and they both have been loaded correctly (I used .getScript to see if colorbox loaded correctly

相关标签:
2条回答
  • 2021-01-23 01:38

    I had the same error appears in Chrome browser.

    In case the solution above didn't helped, #MannyFleurmond solution helped in my case. Try warp the colorbox js call with function($):

     (function($) {
       // Inside of this function, $() will work as an alias for jQuery()
       // and other libraries also using $ will not be accessible under this shortcut
     })(jQuery);
    

    So my ColorBox call look like this:

     (function ($) {
            $('#myelement').click(function (e) {
                e.preventDefault();
                var url = $(this).attr('href');
                $.colorbox({ href: url, width: 936, height: 582, top: 160});
    
            });
        })(jQuery);
    
    0 讨论(0)
  • 2021-01-23 01:47

    You need to reference the colorbox file after the jquery file. Like this:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    <script src="Scripts/jquery.colorbox.js"></script>
    <script src="Scripts/scripts.js"></script>
    

    That is the case for most jquery plugins by the way.

    0 讨论(0)
提交回复
热议问题