2

I'm working on a library which uses jQuery internally which work fine. But I don't want force the user to use my jQuery version just because he uses my library in his code.

So the question is, how can I use jQuery under a different name?

Is it sufficient to do something like this:

var mylib.jQuery = {};  
mylib.jQuery = jQuery.noConflict(true);

This will make jQuery available under mylib.jQuery and free the $ symbol, but the original jQuery symbol still works (which I think is not so good).

2 Answers 2

5

You'd have to go into the source because window.jQuery is defined there, and just update the reference name.

This seems like an unreasonable request though.

Edit: Looks like all you have to do is set the reference to $.noConflict:

<script src="jquery.js"></script>
<script>
var foo = {};
foo.jQuery = jQuery.noConflict( true );
alert( typeof jQuery );
alert( typeof $ );
alert( typeof foo.jQuery );
</script>

You'd have to do this right after you include the script though. My previous way did it directly in the script:

http://173.45.226.115/jquery.html

Sign up to request clarification or add additional context in comments.

1 Comment

Well, noConflict is sufficient for most I suppose, hehe. but yeah I'd update all window. statements in the source code.
1

By specifying true in the jQuery.noConflict(true);, it sets the noConflict to extreme mode and should make it so it won't conflict with any other library. It should be the first thing you define anywhere I'm guessing, so no jQuery code/plugin should appear before the var mylib.jQuery = jQuery.noConflict(true);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.