Side navigation
#12207 closed bug (invalid)
Opened August 06, 2012 04:59PM UTC
Closed August 06, 2012 05:53PM UTC
jQuery.noConflict deletes jQuery replacement variable...
Reported by: | WriterDan | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
There's an example on the jQuery.noConflict page as follows:
*****************************************
Example: Creates a different alias instead of jQuery to use in the rest of the script:
var j = jQuery.noConflict();
Do something with jQuery
j("div p").hide();
Do something with another library's $()
$("content").style.display = 'none';
*****************************************
This method is genius, and I use it quite often. I recently had a problem with it though, because of some code that someone else wrote.
Instead of including:
var j = jQuery.noConflict();
like your example, they used:
var jQuery = jQuery.noConflict();
This seems to work fine in FF, Chrome, Safari, and IE9; however, in IE8 and IE7, it looks like the noConflict directive deletes the new jQuery variable that is being defined by the above statement. That definition was placed outside of any document.ready declarations on this site I was working on, so it looked like jQuery just wasn't loading for IE8 or IE7, which was annoying. At the conclusion of my three-day debug session, I just had to laugh.
The site was using jQuery 1.5, but in amongst my debugging I verified that 1.7.2 behaved the same way.
I don't know if you'd qualify this as a "bug" necessarily or perhaps just poor programming practices on someone else's part, but I had it nailed into my head during graduate school that when building software you shouldn't build it so that it works, you should build it so that it doesn't break. :) Thus, I'm reporting it.
Thanks.
Dan
Attachments (0)
Change History (1)
Changed August 06, 2012 05:53PM UTC by comment:1
resolution: | → invalid |
---|---|
status: | new → closed |
There's no reason to ever do that. The documentation seems pretty clear on this point.
If you say
it removes its use of
$
but leaves thejQuery
object in global scope. No need to declare another variable with the same name.Not sure how we'd make a software change inside jQuery to prevent this error...suggestions welcome though.