jQuery comes to Drupal 4.7

mfredrickson's picture

There have been a few threads on jQuery in 4.7, mostly filled with disappointing tales of incompatibilities of Drupal's JS files and jQuery.

Not being a JS guru, and not wanting to be, I decided to use jQuery for a client project and created a jquery47 module to allow anyone else to use my hacked up jQuery.

You can find it here: http://drupal.org/project/jquery47

To use:

First, a note: to make jQuery compatible with Drupal, I had to rename the $ function to JQ. Sorry, there's really no way around this. When Drupal 5.0 comes out, you'll have to rename all your calls to JQ('...') to $('...').

Write your JS file and put it somewhere. Using drupal_get_path() get your file's path. Call jquery_add_js($yourfilepath) and you're ready to go.



Another approach

Dave Cohen's picture

JQuery does not work in 4.7 because drupal defines the javascript function $() (as does JQuery). So the alternative to your approach is to find every occurance of "$()" in the drupal code and rename it to something else. I renamed mine to $id() (because what the function does is find an element given it's id). Once you've renamed all those calls, you can include jQuery and it's plugins without modification.

No, because that braked

ultraBoy's picture

No, because that braked something else.. I don't remember actually. Approach with renaming $ in jQuery seems better for me.

anybody try jQuery.noConflict();??

jvandervort's picture


and perhaps:

Reassign jQuery to another shortcut
var $j = jQuery;