Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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

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

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

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

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?

share|improve this question
add comment (requires an account with 50 reputation)

1 Answer

up vote 3 down vote accepted

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');
share|improve this answer
Thank you! Works perfectly. – beth Aug 22 '12 at 19:04
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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