I have a module called catalog_menu

I included a js file within this module in this way:

drupal_add_js(drupal_get_path('module', 'catalog_menu') . '/js/catalog_menu.js');

Now in the browser I get this error message:

Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function

I think that the problem is that catalogo_menu.js is loaded before jquery.js (the jquery library)

What is the right way to load a js file which depends on jquery library?

  • Are you using Drupal 7? Feb 17, 2012 at 11:55

2 Answers 2


I actually think it is pretty unlikely that you have a weight problem, unless you redefined your module to have a extremely low weight. Make sure you have JS optimization turned off, and then do a view source and make sure jQuery is the first script loaded (nearly always is).

My two guesses are

  1. You have a JS error somewhere else, and this is a weird side effect.
  2. You have a JS error in your catalog_menu.js (or another file) that is nuking the $ object by accident.

Also, you should you use an anonymous closure or JS module pattern for code, because Drupa 7 defaults jQuery no-conflict mode.

(function ($, Drupal) {
  function init () {

  Drupal.behaviors.catalog_menu = {
    attach: init
}(jQuery, Drupal));
  • I tried just leaving these lines: (but not working at all, not error message neither)
    – chefnelone
    Feb 22, 2012 at 18:56
  • (function ($, Drupal) { function init () { $('.logo-img').hide(); } Drupal.behaviors.catalog_menu = { attach: init }; }(jQuery, Drupal));
    – chefnelone
    Feb 22, 2012 at 18:56

You can change your module's weight to ensure it gets loaded after everything else.

Several ways :

  • SQL the system table (update system set weight=9999 where name = 'mymodule')
  • use the Module Weight submodule from the Util module.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.