Question

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 and I get a positive result). However the function does not load colorbox and Firebug says "$(...).colorbox is not a function". The code used to work but I'm not sure what I did to break it. Here's the header:

<!DOCTYPE html>
<head>
<link rel="stylesheet" href="colorbox.css"/>
<script src="Scripts/jquery.colorbox.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="Scripts/scripts.js"></script>
<script>

$(document).ready(function(){
    $(".popup").colorbox({transition: "elastic", opacity: 0.5, speed: 350});
    var panels = $('.accordionButton > .accordionContent').hide();
    $("div.accordionButton").click(function(){
        panels.slideUp();           
        $(this).parent().next().slideDown();
        return false
    });

});
</script>
</head>

I have checked several times to make sure the script is located in the correct directory. Here is the link:

<div id='supermenu'><table><tr><td><a href='login.php?lang=en' class='popup'>Login</a></td><td> or </td><td><a href='register.php?lang=en'> Register </a></tr></td></table></div>
Was it helpful?

Solution

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.

OTHER TIPS

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top