please simplify the solution for prototype and jquery on the same page!

188 views
Skip to first unread message

geoffcox

unread,
Apr 18, 2011, 8:37:10 AM4/18/11
to Prototype & script.aculo.us
Hello

I read that there is a problem with prototype and jquery being used on
the same page and that the solution involves the use of

jQuery.noConflict()

but I am far from clear how to use this!

I have

1. prototype and soundmanager2.js to play some sounds, and

2. jquery-1.5.1.js and fadeslideshow to run a slideshow, and

3. jquery-1.5.1.js and jquery.featureCarousel.min.js to run a carousel
of images.

and with IE6 I get the error message re line 5734 in prototype.js,
"Object doesn't support this property ot method" - this line having

element.dispatchEvent() on it.

All 1, 2 and 3 work by the way.

How do I prevent the error message?

Cheers

Geoff

joe t.

unread,
Apr 18, 2011, 8:27:42 PM4/18/11
to Prototype & script.aculo.us
<script type="text/javascript" src="/path/to/jquery.js"></script>
<!-- Add in any jQuery plugins here while $ still refers to jQuery -->
<script type="text/javascript">$j = $.noConflict();</script>
<script type="text/javascript" src="/path/to/prototype.js"></script>
<!-- Add any Prototype extensions -->

When you want to use jQuery, use the replaced shortcut call to $j
(this is an arbitrary reassignment - could be anything that
distinguishes it from Prototype's $). Prototype's $ here replaces
jQuery's.
Anything you use to extend jQuery you should load before reassigning
jQuery's $ (i do it for safety, and clarity in my code). Then after
the reassignment, load Prototype and any of its extensions.

i use this setup reliably in my code. Maybe there's more to it than
that, but i have yet to encounter a situation where there's been a
conflict.
-joe t.

geoffcox

unread,
Apr 19, 2011, 5:28:50 AM4/19/11
to Prototype & script.aculo.us
Thanks Joe.
I have also come across a version of soundmanager2 which uses jQuery

http://plugins.jquery.com/node/11402

Cheers

Geoff
Reply all
Reply to author
Forward
0 new messages