1

I got this code here...

<script type="text/javascript">
    $('document').ready(function() {
        alert($('.thickbox'));
    });
</script>

and I put this code in my wordpress theme footer.php file at the bottom. When I went to my page, the alert did not appear, I check my error console and found this error

TypeError: $ is not a function  

$('document').ready(function() {

what gives? my jquery file is in the header, so this should work...or is there a specfic way to put jquery in wordpress?

4
  • If you're including jQuery after that line of script, it won't work as script tags are processed inline. Commented Sep 17, 2012 at 15:47
  • Nope, I am including jQuery first and then that line of code, should work Commented Sep 17, 2012 at 15:49
  • Ahhh man, someone put a link on here and I was totally about to click on it and then bam gone :( Commented Sep 17, 2012 at 15:50
  • Ah, in that case it's probably what JKirchartz suggested.. Commented Sep 17, 2012 at 15:51

3 Answers 3

6

Wordpress's packaged jQuery defaults to noConflict mode, use jQuery('document'), or wrap your code like

(function($) { 
    // Code that uses jQuery's $ can follow here.
})(jQuery);

or in your document ready like this:

jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
});
Sign up to request clarification or add additional context in comments.

1 Comment

thanks JKirchartz...it worked but you have an extra ( at the top
1

try jQuery instead of $

jQuery('document').ready(function($){
    alert($('.thickbox'));
});

Comments

1

'$' is just an alias for 'jQuery'. if $('document') isn't working, try jQuery('document')

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.