Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm using Drupal 7, which uses jQuery 1.4 as default? How can I update it to the latest version (currently 1.7)?

share|improve this question
1  
I don't want use module, want to manuel. –  Karmacoma Apr 19 '12 at 14:26
    
Upgrading jQuery in Drupal manually would be very complicated and risky even for the most seasoned Drupal developers. You should take Clive's advice and utilize jQuery Update. –  sheena_d Apr 19 '12 at 14:32
    
I go to misc-jquery.js file via ftp and replace new jquery code. Right? –  Karmacoma Apr 19 '12 at 14:33
    
misc-jquery.js isn't exact same copy of a jquery version, as far as I know. However, according to git, drupalcode.org/project/jquery_update.git/tree/refs/heads/… , there should could be a 1.7 support too. –  Ayesh K Apr 20 '12 at 2:12
    
@Patrick Kenny I don't think that's correct - I can select jquery 1.8 using jquery_update as of today –  doub1ejack Oct 31 '13 at 17:13
add comment

5 Answers

up vote 27 down vote accepted

One way is to install the dev version of jQuery Update, which gives you the option to use jQuery 1.7 (by visiting the settings page at http://mysite.com/admin/config/development/jquery_update).

Beware though, currently it's known to break JavaScript elsewhere in the site (for example the widget dropdown on a Manage Fields page will no longer work). If you're prepared to fix up that, and any other small annoyances, this is probably your best bet. You should also note that using the dev version of a module isn't without risks, as the chances of it having bugs is a lot higher than using a specific release.

If you want to do it manually then you'll have a lot of core javascript code to rewrite to make your site work as expected; jQuery changed an awful lot between version 1.4/1.5 and 1.7 so a lot of the core Drupal javascript code simply won't work with it.

If you want to just drop in a version of jQuery 1.7 then you could probably implement hook_js_alter(), unset the core jQuery file, and add your own in it's place:

function MYMODULE_js_alter(&$js) {
  $path = drupal_get_path('module', 'MYMODULE') . '/path/to/jquery.1.7.js';

  // Copy the current jQuery file settings and change
  $js[$path] = $js['misc/jquery.js'];

  // Update necessary settings
  $js[$path]['version'] = 1.7;
  $js[$path]['data'] = $path;

  // Finally remove the original jQuery
  unset($js['misc/jquery.js']);
}

Once you've done that, open up Developer Tools/Firebug and you'll see all the changes you're going to need to make to get the rest of the site JS to work :)

UPDATE

The latest version of jQuery update (7.x-2.3 at time of writing) will now allow you to update jQuery to v1.8. Very cool.

The jQuery Multi module is another option, thanks to goron for pointing that out in the comments. As he also notes, this module has a stable release and won't break any existing javascript.

share|improve this answer
    
Thaks man!!! I've been looking for this for a while! In my case I just wanted to load a different version of jQuery per theme, so I just replaced MYMODULE_js_alter for MYTHEME_js_alter and drupal_get_path('theme', 'MYTHEME') for drupal_get_path('module', 'MYMODULE') –  victmo Aug 10 '12 at 17:29
1  
Beware, Drupal comes with its own set of JavaScript files written to work with an old jQuery and non-compatible with jQuery 1.7 or 1.8. The latest jQuery Update provides replacement files for these. –  Pierre Buyle Oct 20 '12 at 14:40
1  
You need the dev version of the module, the stable version doesn't have the option for 1.7 –  Clive Nov 6 '12 at 9:21
2  
jQuery Multi is another option, which doesn't require the dev version, and won't break any JS. Maybe add it as an option or remove "The only way"? –  goron Oct 31 '13 at 22:53
1  
@goron Good point, thanks. Some of this answer is probably obsolete now I'll try to update it soon –  Clive Oct 31 '13 at 23:07
show 1 more comment

You should also consider to use the jquery multi module which allows you to use more than one version of jquery. Great module, I'm using it for Druapl 7 and 6 on all of my projects.

share|improve this answer
add comment

Inspired by hook_js_alter documentation, the following works. You can place it in your theme's template.php. This requires that you use a different admin theme to avoid conflict with Drupal core, and it assumes that jquery-1.8.3.min.js is located in a folder called 'js' within the theme (adjust to suit).

function [theme_machine_name]_js_alter(&$javascript) {

  $javascript['misc/jquery.js']['data'] = drupal_get_path('theme', '[theme_machine_name]') .
    '/js/jquery-1.8.3.min.js';

  $javascript['misc/jquery.js']['version'] = '1.8.3';

}

share|improve this answer
    
Requiring a different admin theme is not really a solution, unless you can provide a list of themes that will work with this method. My guess is it would be very, very few. Plus those themes would be very likely also to use jQuery, which would pretty much definitely lead to the problems that the jQuery update module was specifically designed to fix –  Clive Feb 15 '13 at 15:23
add comment

I'm not sure what your purpose is here, but when I needed a specific version for custom module development I have been able to do so by using jQuery.noConflict.

It is some extra work compared to the jquery_update module (which the OP doesn't seem to mind), but it does mean that you don't have to worry about whether you're going to mess up your whole drupal installation.

share|improve this answer
add comment

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.