Using jQuery and Prototype together

Share

Yes. You can use jQuery and Prototype together in the same page.

I have been using jQuery and Prototype for quite some time now. But have always used them on different projects knowing for sure that if not anything else, their ‘$’ would clash.

However I found out a solution.

By default the ‘$’ in jQuery is used as the shortcut for the “jQuery” namespace. To override the default jQuery.noConflict() needs to be called after the js files have been included. After that jQuery can be called with “jQuery” instead of ‘$’ and hence there would be no confusion between the js frameworks.




Now using “jQuery” instead of ‘$’ can be irritating. To use a short name create one like below –

var $j = jQuery.noConflict();

Now you can use jQuery like –

$j(“div”).hide();

This entry was posted in Javascript, jQuery, Prototype and tagged , , . Bookmark the permalink.
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*