views:

75

answers:

5

Hello,

I'm implementing jQuery in a site and am getting the "$ is not a function" in Firefox when I try to use a selector, but $(document).ready() works perfectly right before it. My code looks like this

<script>
     $(document).ready(function(){
          alert("hi")
     }); // Works fine
     function showDiv(){
          $("#traditionalCC").hide();
     }
     //Throws error
</script>

Does anyone know why this happens, and why it works in Chrome and Firefox.

A: 

Try

<script> 
   $(function() {
      alert("hi") 
    }); // Works fine 
    function showDiv(){ 
      $("#traditionalCC").hide(); 
    } 
    //Throws error 
</script> 
cfEngineers
first function still works, but the selector still throws a $ is not a function error
john m.
A: 

Try to use

$(document).ready(function() {
      $ = jQuery.noConflict();
});

Fix your script declaration to <script type="text/javascript">

Verify if your script is after the jQuery lib include.

I hope it help.

pedrorezende
Script is after the jQuery lib include... doing $ = jQuery.noConflict(); throws the error "jQuery is not defined"
john m.
+1  A: 

The key difference between your two examples (the working and non working ones) is that the first one is using the document ready event. That happens when the page is fully loaded. Not sure when you're other one is getting invoked, but my guess is that it is being called before your <script> tag include for jquery.js itself.

Kirk Woll
I thought this was the correct answer when I wrote it (obviously), but now I'm not so sure. The document-ready event is using jQuery itself, of course, when you're attaching the event, so should have been available to any code that follows it.
Kirk Woll
A: 

I have found that sometimes Firefox gets "hosed" and I have to quit and relaunch.

Mike Erickson
A: 

In case anyone comes across this in the future, the problem was FireBug. I uninstalled and reinstalled and the issue went away.

john m.