jquery: $ is undefined

I run a wordpress blog.
It includes Jquery

<script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.12.3'></script>
<script type='text/javascript' src=/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.0'></script>

When I run jQuery
I got:

Read More
function (a,b){return new n.fn.init(a,b)}

when I try

$("div") 

I got

Uncaught TypeError: $ is not a function(…)

when I try jQuery("div")

I got:

a.fn.init[203]

How can I use Jquery ?

Related posts

3 comments

  1. $ is an alias of the jQuery() function, which apparently missing in this case…

    One way is to do, between jQuery and your other scripts:

    <script type="text/javascript">
        var $ = jQuery;
    </script>
    

    It should work

  2. It looks like jQuery is not bound to the $ variable (to avoid conflicts, probably).

    If you want to use the $ variable then you can create a scope wherein it will be bound to that variable:

    (function ($) {
        // Use $ in this scope
    }(jQuery));
    

    If all your code should run when the document is ready (which is usually how it is done) then you can also use the scope that jQuery creates for you:

    jQuery(function ($) {
        // Document ready, use $ in this scope...
    });
    

    You can also just add jQuery to a global $ variable. If you know for certain that only jQuery will be using that variable then it is probably fine.

    $ = jQuery;
    

Comments are closed.