1

I am getting "TypeError: $ is undefined" in Firebug when I call the drupal_add_js on an external jQuery file. If it were some local code, I would just wrap the code in a behavior function, like so:

(function($) {
    Drupal.behaviors.addStuff = {
     attach: function(context, settings) {
       // jQuery code goes here.
     }
    }
 };

I know that I'm supposed to change the dollar signs to "jQuery." but I can't do that to an external file (since I can't edit the code). How do I safely include this file? Note that this is just one module, I do not want to add it to my template file, and I do not want it to run on every page on my site.

1
  • 1
    You'll have to run jQuery in conflict mode then, which is as simple as adding window.$ = window.jQuery. Of course that won't take into account any conflicts that arise, but that's just a standard JS, not something Drupal can help you solve
    – Clive
    Commented Oct 19, 2016 at 18:01

0

Your Answer

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

Browse other questions tagged or ask your own question.