How do I change the jQuery version used for a form with a specific form ID?

1 Answer 1


What you would like to achieve is loading another version of jQery in your form page. You need to understand the way hook system works. hook_js_alter() is defined as:

"Perform necessary alterations to the JavaScript before it is presented on the page."

You can use the above hook to change jQuery version. hook_form_alter() is defined as:

Perform alterations before a form is rendered.

So, first action is hook_js_alter() and second action is hook_form_alter(). You cannot change jQuery version with the second hook, but you can use the following code.

function mymodule_js_alter(&$javascript) {
  if ($_GET['q'] == "node/add/page") {
     // Swap out jQuery to use an updated version of the library.
  $javascript['misc/jquery.js']['data'] = drupal_get_path('module', 'jquery_update') . '/jquery.js';

For more information on using newer versions of jQuery you can refer the Drupal.org article which explains how to add Newer versions selectively using various methods.

  • 1
    i did something like so if($_GET['q']=='node/add/data-definition'){ $path = drupal_get_path('module', 'equations') . '/js/jquery.1.7.2.min.js'; $js[$path] = $js['misc/jquery.js']; $js[$path]['data'] = $path; unset($js['misc/jquery.js']); unset($js['misc/ui/jquery.ui.core.min.js']); } and it worked well Commented Mar 9, 2014 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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