views:

510

answers:

2

Hi Guys,

I am trying to use jQuery in a highly conflict environment. .noConflict() doesn't work and I am trying to do something like

<script type="text/javascript">
document.write(    document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
jQuery.noConflict();
var $ = jQuery;
</script>

Any ideas how to fix this ?

A: 

Are you sure it has nothing to do with the fact that you have:

document.write(    document.write(unescape(...longstringhere...)); // Missing final close paren?

That would cause an error and then noConflict wouldn't work.

Also, do you need to be using Prototype and jQuery at the same time? The whole purpose of jQuery.noConflict() is to NOT set the jQuery variable to $ because Prototype uses it (I'm sure there are other reasons, but that's the main one in this case). jQuery and Prototype aren't good friends, usually.

Finally, are you absolutely positive (assuming you don't have the syntax error in your real code) that jQuery is getting loaded?


Did some quick research. Check this link and see if it helps any:

http://docs.jquery.com/Using_jQuery_with_Other_Libraries

Basically, you might have to call jQuery first, and you will have to call Prototype BEFORE you use noConflict()

Jeff Rupert
thanks - it was the order :))
Tom
You're welcome! Glad I was able to help you solve the problem. =)
Jeff Rupert
A: 

Don't use $ - that is the source of the conflicts. Substitute jQuery wherever you'd normally use it, like so:

jQuery('#my-id')
jQuery('.my-class')

and so on

K Prime