How to use jQuery in Magento aka jQuery Compatible Mode

Magento shop is using PrototypeJS library which is registering $ for itself. jQuery library wants to do the same thing, that’s why in order to use jQuery in a website which uses PrototypeJS (or similar library) you need to put it into Compatibility Mode. How?
Instead of:

$(document).ready(function(){
$("div").hide();
});

you need to write your code this way:

var $j = jQuery.noConflict();
$j(document).ready(function(){
$j("div").hide();
});

So as you noted the difference is adding: var $j = jQuery.noConflict();
and using $j instead of $.

You can read more on this subject here: Using jQuery with Other Libraries

This entry was posted on Tuesday, April 5th, 2011 at 9:26 pm and is filed under JavaScript. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “How to use jQuery in Magento aka jQuery Compatible Mode”

  1. martin Says:

    thank you very much, I would never found alone

Leave a Reply

 
TopOfBlogs Web Development & Design Blogs