I would like to execute the jQuery $(document).ready() in a drupal site. While i know that i can just stick it in the index page , this is really messy and a hack.
What i want to know is where is the correct location to put this, it would also need to be theme specific as i dont want all themes to use it.
Thanks in advance for the help.
Sweet success , thanks both of you for the help , i just have one last amend to this question. Now that i have got this far , i need to execute the jQuery code to update the document , can i use the context to modify the document ?
VonC adequately answered the ‘how’ part of the question, so I’ll focus on the ‘where’ part.
If the script is theme-specific, then the natural place to put the script file is in your theme. The problem is that by the time Drupal gets to the theme, the
$scriptsvariable has already been ‘rendered’ (in Drupal parlance) into HTML. To add a script in the theme layer, you need to add the script and rebuild the$scriptsvariable.Assuming you’re using Drupal 6, this would go in your
theme_preprocess_page()function:Just change the second argument of
drupal_get_path()to reflect the name of your theme, then change the name of the script file fromexample.jsto whatever you’ve named your script.