Html – $(…).fancybox is not a function

fancyboxhtmljquery

I'm trying to run the jQuery fancybox tool and I keep running into the same problem. The Firebug debugger highlights the first snippet of jQuery code and says that "$(…).fancybox is not a function". Here is the basic code that I am trying to run this with. Any ideas on how I can fix this?

<!doctype html>
<html>
    <head>
        <title>FancyBox Test</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
        <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css" media="screen">
        <script type="text/javascript" src="/fancybox/jquery.fancybox.pack.js"></script>
        <script>
            $(document).ready(function() {
                $('.fancybox').fancybox();
            }); 
        </script>
    </head>
    <body>
        <a href="images/1.jpg" class="fancybox" rel="gallery" title="Sample title 1">
            <img src="images/1.jpg"  width="150" height="100">
        </a>
        <a href="images/2.jpg" class="fancybox" rel="gallery" title="Sample title 1">
             <img src="images/2.jpg"  width="150" height="100">
        </a>
        <a href="images/3.jpg" class="fancybox" rel="gallery" title="Sample title 1">
            <img src="images/3.jpg"  width="150" height="100">
        </a>
        <a href="images/4.jpg" class="fancybox" rel="gallery" title="Sample title 1">
            <img src="images/4.jpg"  width="150" height="100">
        </a>
     </body>
</html>

Best Solution

Try adding following code in your Page HTML header. (Before Fancybox function is called)

<script type="text/java script">
 var $= jquery.noConflict();
</script>