Ticket #6719 (closed bug: worksforme)
jQuery.noConflict() leaves $ undefined
| Reported by: | sebringj | Owned by: | |
|---|---|---|---|
| Priority: | Milestone: | 1.4.3 | |
| Component: | unfiled | Version: | 1.4.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
jQuery.noConflict() will leave $ undefined if no previous library has claimed it. The behavior should keep the $ defined if jQuery is the only library claiming it. The work around was this:
jQuery.noConflict(); if (typeof(window.$) === 'undefined') { window.$ = jQuery; }
The scenario is useful when loading in dynamic scripts that depend on jQuery and will load in jQuery if jQuery is undefined but then will allow other libraries to use the "$" or will leave the "$" defined to jQuery. The "$" is defined in other script libraries so this is necessary but it is not necessary for "jQuery" as it would be silly to support that if an idiot decided to define that. The "jQuery" fallback code should be taken out in my opinion to give room for this scenario as it is more likely than "jQuery" being defined from another library or code outside of the jQuery official code base.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

I don't think we'll be changing this, it's been documented behavior for several years now and your solution works fine for the situation where you want it that way.