javascriptdrupaldrupal-themes

customizing order of Javascript Loading in drupal & adding a new JS to that list


I want to customize the order of loading javascripts in drupal 7. I am using Bartik theme. If I want to add a new JS and load it somewhere in between those list. How can I achieve the same? Thanks


Solution

  • You have to use drupal_add_js function

    The second parameter is $options, that you can pass the group of your Javascript file

    Also you can pass the weight of your script to define the order you want.

    Here is an example

    drupal_add_js('jQuery(document).ready(function () { 
      alert("Hello!"); });', 
      array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)
    );
    

    I recommend you to read this article: Managing javascript in Drupal 7