$ is not a function

<script type="text/javascript" src="framework/resources/jquery-1.5.1.js"></script>
<script type="text/javascript">
      var blink = function() {
            $('#blink').toggle();
       };
</script>

Throws an error saying

$ is not a function

When using an external JavaScript file which gets referred after jQuery I can only seem to use jQuery within the ready function. Is there something I should know about using jQuery in this manner?

Answers:

Answer

That error means jquery isn't loaded

Answer

jQuery may be conflicting with another definition, the fact that you can use it in the ready function seems to indicate that it is at least loaded. Have you tried using:

<script type="text/javascript" src="framework/resources/jquery-1.5.1.js"></script>
<script type="text/javascript">
      var blink = function() {
            jQuery('#blink').toggle();
       };
</script>

Sometimes it is cleaner to go direct to the object. If you find that resolves your problem you may wish to switch to noConflict mode which is described in more detail in the docs here:

http://api.jquery.com/jQuery.noConflict/

Hope that helps.

Answer

Have you referenced jQuery as the first script in your page? Does the path exist? Try using Google's, just to test:

<script type="text/javascript" 
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
</script>
Answer

It seems that jQuery is conflicting with any existing javascript library.

I hope this link might help.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.