I'm using jQuery accordion effects to display some information. I include the libraries:

    drupal_add_js('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', file);         
    drupal_add_js('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js', file);

Those seem to work fine, since after including them I can paste


into scratchpad and I get the functionality I want.

However, if I try to add it to my function like so:

drupal_add_js('jQuery(".accordion").accordion({collapsible:true,active:false});', inline);

...nothing happens. I've tried some variations, such as


as well as moving the drupal_add_js() call further downstream in my code, so it appears after the elements it acts on are created and rendered.

How do I get this little snippet of code to run on my page?


You're most of the way there! You just need to convert what's in your ready() to a function:

drupal_add_js('jQuery(document).ready(function(){jQuery(".accordion").accordion({collapsible:true,active:false})});', 'inline');

Also, according to docs you should change your googleapi calls from file to 'external',

drupal_add_js('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', 'external');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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