I've written a javascript that for some reason whenever I run it, it removes any hover events. Since I am running my site with nice menus I would like to run my script as high up in the $script array as possible.

I added this line to the template.php:

drupal_add_js('sites/itascacg.com/themes/custom/icg/js/fixtitles.js',array('type' => 'file', 'weight' => -19));

since according to the documentation I've read jQuery itself is at weight -20, but no matter what weight I give my script i won't float any higher on the list.

does anybody have anybody have any ideas how to push my script up, or at worst push all the other scripts down?

P.S. I'm using drupal 7


2 Answers 2


In what function in template.php are you adding this? A preprocess function I hope.

Anyway, you have to set the 'group' option as outlined on the drupal_add_js page. eg.

drupal_add_js('sites/itascacg.com/themes/custom/icg/js/fixtitles.js',array('type' => 'file', 'weight' => -19, 'group' => JS_LIBRARY));

drupal_add_js states

weight: A number defining the order in which the JavaScript is added to the page relative to other JavaScript with the same 'scope', 'group', and 'every_page' value.

The exact ordering of JavaScript is as follows:

  1. First by scope, with 'header' first, 'footer' last, and any other scopes provided by a custom theme coming in between, as determined by the theme.
  2. Then by group.
  3. Then by the 'every_page' flag, with TRUE coming before FALSE.
  4. Then by weight.
  5. Then by the order in which the JavaScript was added. For example, all else being the same, JavaScript added by a call to drupal_add_js() that happened later in the page request gets added to the page after one for which drupal_add_js() happened earlier in the page request.

Weight is at number fourth. Please update your scope, group and every_page parameters.

Secondly try a very smaller number for weight i.e -100000. It may work for you.

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.