javascriptjquery

jQuery error: "$ is undefined"


I'm using a enhanced version of Lightbox called SexyLightbox. It uses jQuery as its framework. When I initialize it, I get this error on regular invervals when the Lightbox isn't running and an infinite amount of times when I attempt to show a picture:

Error: $ is undefined
Source File: http://bagelstreet.se/sexylightbox/sexylightbox.v2.3.jquery.min.js
Line: 12

The initialization script goes as this:


    <link rel="stylesheet" href="sexylightbox/sexylightbox.css" type="text/css" media="all" />

    <script type="text/javascript" src="sexylightbox/jquery.min.js"></script>
    <script type="text/javascript" src="sexylightbox/jquery.easing.1.3.js"></script>

    <script type="text/javascript" src="sexylightbox/sexylightbox.v2.3.jquery.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function(){
          SexyLightbox.initialize({color:'black', dir: 'sexyimages'});
        });
    </script>

UPDATE So - I've replaced the library, I'm using the unpacked version of sexylightbox. FireBug points out the error on the jQuery.bind() function, specifally on the bolded line:


jQuery.bind = function(object, method){
  var args = Array.prototype.slice.call(arguments, 2);  
  return function() {
    var args2 = [this].concat(args, $.makeArray( arguments ));  
    return method.apply(object, args2);  
  };  
};  

jQuery version being used is 1.3.2.

Any thoughts on what might be happening?

Solved

Problem was a coding error on SexyLightbox author's code. Used $ on jQuery.bind() before $ is defined.


Solution

  • Something in sexylightbox.v2.3.jquery.min.js is causing $ to be set to undefined. If you set a break point before that file loads, $ is correctly an alias for jQuery. I would try loading a version of sexylightbox.v2.3 that hasn't been run through Packer. That way you can properly use Firebug to figure out what is going on.