How to include js file in a module which depend on jquery? 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?
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


You have a JS error somewhere else, and this is a weird side effect.
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 () {
    $("body").addClass("catalog-menu");
  }

  Drupal.behaviors.catalog_menu = {
    attach: init
  };
}(jQuery, Drupal));