Usually this is because it’s an older site that was original written using Prototype and we’re migrating it over to jQuery. Or other times it’s just easier to use an existing jQuery plugin for something than to write a few dozen lines of Prototype from scratch.
It’s easy to run jQuery in parallel with other libraries thanks to jQuery’s noConflict mode which makes jQuery stop using the $ variable.
“But", you say, “Having to type jQuery.whatever() over and over is so hard compared to typing $.whatever()."
Well, my friend, today is your lucky day. I have a solution for you that will save you characters of typing. Characters!
If all of your code is happening inside of a jQuery.ready() event, you can do this:
In the example above, jQuery is passing itself to the ready() function handler. That means any code instead the ready handler can use $ to access the jQuery object.
And if your jQuery code isn’t inside a ready() event? Still easy to handle:
In this case, we wrap all of our code in an anonymous function that calls itself, passing in the jQuery object as a single parameter. Now all of the code inside the anonymous function can use $ to access the jQuery object.