jQuery Ready Plus $ Conflict Resolution

jQuery logo

Earlier in my notes to uses, I mentioned the method to initialized jQuery by using the jQuery ready pattern. However at the time, I did not mention how to deal with $ conflict problems. The $conflict problem is significant. You would like to know that you are using the jQuery $ and it is correctly being interpreted in you code. Sometimes, when used in PHP or with additional libraries like prototype, the meaning of $ gets confused. Fortunately, it is VERY easy to assure that the $ is correctly interpreted in any script found in the jQuery ready initialization. Option1, use the following setup as the jQuery Ready.



Query(document).ready(function( $ ) {
    // Your jQuery code here, using $ to refer to jQuery.
});

 

If you would prefer to use the shortcut pattern for jQuery Ready, use the following:



jQuery(function($){
    // Your jQuery code here, using the $
});

 

That’s it for now …

Leave a Reply