Sam Ivichuk
Sam Ivichuk

Reputation: 1028

Drupal 7 : jQuery doesn't work at all

I am writing a module for Drupal 7, that has 3 submodules. All submodules have their own module, style and js files. In the init function of each submodule I include all javascript files that module uses:

  drupal_add_js(path);

Everything works fine except jQuery. I tried different ways:

  (function ($) {
     alert("1");    
  })(jQuery);

  alert(jQuery('div'));
  alert($('div'));

and nothing happening. Tried to use jQuery as inline function in my module file:

  drupal_add_js("(function ($) {alert('1');})(jQuery)","inline");

it doesn't work too.

Week before everything worked fine, even popup menus and ajax, based on jQuery. But then I rewrote php functions, add functionality and optimized queries(I haven't modified js files that worked correctly). Maybe I have changed some server configuration files too(I use Denver and run project on localhost).

Only now I realized that my jQuery doesn't work, I have tested everything, spent already 2 days searching for an answer. I know that I made some silly and simple mistake but I can't find where it is. Maybe someone already had such problem, help please.

P.S.: it's my 1-st post here, please don't judge me too harshly

Upvotes: 1

Views: 1793

Answers (1)

Web Assistant
Web Assistant

Reputation: 711

I would disable js aggregation (if enabled), then check the source code to see if the path to those JS files are correct. If so, I would use Drupal.behaviours around your js as described here http://drupal.org/node/756722#behaviors If that doesn't work, I would check if there are no js errors popping up somewhere.

Upvotes: 1

Related Questions