0

What might cause Firefox to tell me $ is not defined, but using 'jQuery' works as expected.

I'm on Wordpress 3.4 and Wordpress comes packaged with jQuery. Is it something specific to Wordpress?

3
  • Would a moderator care to tell me why my comment was deleted? Commented Nov 6, 2012 at 19:58
  • @MatthewBlancarte Huh? I have no idea what your deleted comment was. I posted mine for Jim, independently. Commented Nov 6, 2012 at 22:07
  • @Blazemonger Lol my apologies. I left the same "accept your previous answers" comment and mine was deleted by some random admin. Commented Nov 6, 2012 at 22:18

2 Answers 2

8

jQuery.noConflict() has been called. To resolve this with a minimum amount of code change do this.

Before:

$("your").code(function () {
  $("that").uses($.all("over").the("place"));
});

After:

(function ($) {
  $("your").code(function () {
    $("that").uses($.all("over").the("place"));
  });
})(jQuery);
2
  • 2
    Do you ever get the feeling that your computer is... talking to you? Commented Nov 6, 2012 at 19:45
  • @Blazemonger No, because there is very probably other code that relies on $ not being jQuery (otherwise there'd be no reason to use noConflict() in the first place). Your suggestion would fix one bit of code and break the other.
    – Tomalak
    Commented Nov 6, 2012 at 19:49
6

jQuery works in noConflict mode inside wordpress as the docs state: http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_wrappers

1
  • Wow. Thanks for that useful bit of info!
    – JamesHoux
    Commented Nov 8, 2012 at 4:56

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.