Geeks With Blogs
Paolo del Mundo Senior Consultant at Excella Consulting

My current project involves integrating legacy Prototype code with jQuery. Normally the solution would be to just change all the $(object) references to jQuery(object). However, one of the constraints was I couldn't modify any of the jQuery code, and Prototype does NOT give you any way to rename the $ variable.

I discovered this hack while trying to find a way around this:

<script type="text/javascript" src="jquery-1.2.3.min.js"></script>
<script type="text/javascript" src="prototype.js"></script> 
<script type="text/javascript" src="jquery-1.2.3.min.js"></script>

The first two lines were there by default (it was being generated by the Master Page, which I could not modify). Apparently, if you register the external jQuery library the second time around, jQuery co-opts the $ variable for itself. This allowed me to use the $ symbol for jQuery.

Posted on Sunday, February 1, 2009 10:28 AM | Back to top

Comments on this post: A Hack for jQuery/Prototype Collisions

# A Hack for jQuery/Prototype Collisions
Requesting Gravatar...
I working in local search marketing company. I have much knowledge about SEO. But I have interest in web designing and developing. I feel very hard HTML coding and other queries. Hacking is my passion. But this article is very helpful for me. Yeah its very beneficial information.
Left by Hank on Mar 10, 2010 4:10 AM

# re: A Hack for jQuery/Prototype Collisions
Requesting Gravatar...
how would you hack something like this

<script src="/slideshow/scripts/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
<script src="/slideshow/scripts/mootools-1.2-more.js" type="text/javascript"></script>
<script src="/slideshow/scripts/ReMooz.js" type="text/javascript"></script>
<script src="/slideshow/scripts/" type="text/javascript"></script>
<script type="text/javascript" src="Default_jQuery.js"></script>
Left by josh on Mar 28, 2010 7:09 AM

# re: A Hack for jQuery/Prototype Collisions
Requesting Gravatar...
Some questions for you:

1. What are the problems you are encountering in this scenario?

2. What is the version of the jquery in Default_jQuery.js?

Left by Josh on Mar 28, 2010 6:38 PM

# re: A Hack for jQuery/Prototype Collisions
Requesting Gravatar...
<script> alert("hai")</script>
Left by dcxvxc on Feb 11, 2013 11:43 PM

Your comment:
 (will show your gravatar)

Copyright © Paolo del Mundo | Powered by: