0

The following code is having some problem with the jQuery.

<script type="text/javascript">
        $(window).load(function() {
            ..
        });
    </script>

If I include jQuery in the document head and then use the above code, it will work fine. However, if I use include jQuery using the Wordpress function wp_enqueue_script, I get following error: $ is not defined. I can see from the page source that the jQuery is loaded properly in the header. How can I fix it?

2 Answers 2

3

Use the word jQuery instead of $ and pass it a $ reference

jQuery(function($) {
    // you can use $ here
    $(window).load(function() {
        ..
    });
});
Sign up to request clarification or add additional context in comments.

Comments

2

Use jQuery with a capital Q instead of $ to make it work. Wordpress usually includes a script which calls jQuery.noConflict() at the end, leaving $ undefined.

jQuery(function($) { //jQuery passed in as first param, so you can use $ inside
   // use $
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.