Making $ globally accessible with jQuery.noConflict()

The Codex promotes this method of using $ inside a plugin/theme JavaScript file:

jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function
});

But if you do that you only have access to $ inside ready(). I think functions should be broken into small modules which are called from ready(), not all lumped together inside ready(), so if I use the Codex’s method then I have to pass $ to each function, which is annoying and crude. Writing out jQuery all the time instead of just using $ is also annoying.

Read More

I can just do $ = jQuery.noConflict(); at the start of my JavaScript file and then $ is available everywhere, but I suspect that that might cause problems with other plugins/themes in some situations. My searches haven’t turned up any thorough explanations or definitive answers. Does anyone have any thoughts?

Related posts

Leave a Reply

2 comments