0

I've not really found a definitive answer for this question. I've had to edit jQuery plugins to replace instances of $. This, for me at least, is a serious issue. Anyone coming after me, if going to have a nightmare to maintain of upgrade my work. I use a lot of plugins.

Is this really the only option?

2 Answers 2

2

If the plugin is poorly written then I guess you could try using the jQuery.noConflict method.

If it's properly written you don't need it because it will already wrap all $ usages in an anonymous method:

(function( $ ) {
  $.fn.myPlugin = function() {

    // Do your awesome plugin stuff here

  };
})( jQuery );
Sign up to request clarification or add additional context in comments.

Comments

2

As Darin has mentioned, well authored plugins are wrapped in an anonymous method. You can use the same trick in your own code too, rather than use noConflict - for example if you had a JavaScript file with loads of jQuery in it that you didn't want to update:

(function ($) {

    $(document).ready( function () {
        $('#myid').hide();
    });

    // and so on...

}(jQuery));

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.