$(".scrollable").scrollable is not a function

oompahloompah picture oompahloompah · Mar 13, 2011 · Viewed 14.7k times · Source

I am getting the error : $(".scrollable").scrollable is not a function when I attempt to use the scrollable

<html>
<head>
<script type="text/javascript" src="http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"></script>
</head>
<body>
<script>
$(function() {
  // initialize scrollable with mousewheel support
  $(".scrollable").scrollable({ vertical: true, mousewheel: true });
});
</script>
</body>
</html>

Can anyone see what is causing this?

[Edit]

After Mark Hildreth pointed out that the library I was using already bundles jQuery, I removed my Google jQuery CDN reference (not shown above), and then I got the '$ is not a function' error.

I knew then that jQuery was clashing with flowplay, so I updated my pages to use

jQuery.noConflict();
jQuery(document).ready(function()){
   // jQuery('#foo) .... etc
});

This is mildly annoying, as I have to change the script in my existing pages to use jQuery instead of $.

Is there anyway I can continue to use $, or do I HAVE to use jQuery ?

Answer

Justin Obney picture Justin Obney · Sep 19, 2012
// you don't have to use jQuery(document).ready(function()){});
// or noConflict

$ = null; // doean't matter here what happens to $

// just wrap your jQuery code passing in jQuery...
(function ($) {
    //write jQuery here...
    $(".scrollable").scrollable({
        vertical: true,
        mousewheel: true
    });
})(jQuery);