I am using Drupal 7 and bootstrap theme, I also have installed jquery update module,

Now I have created a js (jquery) file and saved it under js folder in bootstrap theme, I tried to call my js file in the info file using script[] = '...', the console then suggested that '$ is not a function', which means my js file was called before jquery was called.

Then I decided to call the my js file from template.php:

function bootstrap_preprocess_html(&$variables) {
  $options = array(
    'group' => JS_THEME,
  drupal_add_js(drupal_get_path('theme', 'bootstrap'). 'js/product_pages.js', $options);

then the following line showed up in the console:

GET http://localhost/Brompton/sites/all/themes/bootstrapjs/product_pages.js?mpprnf 404 (Not Found) 

I am confused, how exactly can I get jquery work properly here?

closed as too broad by Mołot, Triskelion, monymirza, niksmac, AjitS Jul 12 '13 at 6:48

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Hello and welcome. Please read this introductory text, especially Using jQuery and Behaviors parts of it. "which means my js file was called before jquery was called." is false, it only means your file uses jQuery without proper namespacing. – Mołot Jul 10 '13 at 9:51

Technically you've got two Problems. The first one is namespacing, like Molot pointet out. To use $ for jQuery you need at least to wrap your code into this construct:

(function ($) {

That's enough for getting your code executed, for the drupal way you need to attach a behaviour to the Drupal object like the tutorial in Molot's link shows.

The second problem is a missing slash in your drupal_add_js:

drupal_get_path('theme', 'bootstrap') . '/' .'js/product_pages.js'

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