Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#4988 closed defect (bug) (invalid)

Included jQuery library 1.1.4 may be defective

Reported by: ionfish Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.3
Component: Administration Keywords:
Focuses: Cc:


There's something - not sure exactly what, given that I can't read a Gzipped JavaScript library - wrong with the included version of jQuery, 1.1.4. A previously working script (on a plugin-generated admin page) that requires jQuery's $ function (the alias for the jQuery object) no longer works, and Firebug gives me this error:

$ is not a function
[Break on this error] $(document).ready(function() {

You can see my script here:


I have tried including several different versions of jQuery, downloaded from the jQuery website. The 1.1.4 uncompressed and compressed versions work fine (there are no errors and my script runs as intended), as do the 1.2 uncompressed and compressed version. The error only occurs when using the jquery.js file included with WordPress.

I also thought my WordPress installation might not have downloaded that file correctly, so I deleted it and updated again from the repository (I'm running the svn trunk). That produced the same problems as before. My conclusion is that the included jQuery file may be defective in some way. I'd appreciate it if people could test this out and corroborate my findings. I know there was a plan to switch to jQuery 1.2 and that ought to fix the problem, but since it's not been done yet (and may not be until the next version?) a fix for this - if it is indeed a WordPress problem - would be most welcome.

Change History (4)

#1 @Nazgul
14 years ago

The only difference between the "clean" 1.1.4 jQuery and the one bundled with WordPress is that the latter runs with jQuery.noConflict. *1

I don't have much jQuery experience, so I can't help you much further, but you could try switching from $ to jquery. as mentioned on that page and see if that helps.

1 http://docs.jquery.com/Core/jQuery.noConflict

#2 @DD32
14 years ago

  • not sure exactly what, given that I can't read a Gzipped JavaScript? library -

You can replace the file with the uncompressed version for development if you wish.

Since WP uses Prototype in places(Or at least still includes it) Prototype gets the $ variable. (As it was included first, its backwards compatibility)

To work around that, jQuery has allowed for a $.noConflict() mode which jquery operates in with WP, when noConflict mode is enabled, jQuery no longer uses the $ value, only the jQuery value. (ie. $.function() = jQuery.function() )

Previously, when noConflict was enabled, $ would still stay assigned to jQuery if nothing else was using it, in the latest however, when no conflict is enabled, it seems that $ is no longer assigned. (It seems this is to do with the "Any Name jQuery" function: http://jquery.com/blog/2007/08/24/jquery-114-faster-more-tests-ready-for-12/ )

Theres a work around for this too, allthough, i'm not sure of it, someone else will hopefully be able to give the correct syntax, but from pure memory its something like this:

jQuery( function($){
//Use $ here

Personally i've added this to the top of a few options pages for my plugins:

$ = jQuery;

So, What i've been trying to say, is that its the noConflict() mode which will be breaking your script.

Also, as a side note, The reason 1.2 isnt included in 2.3 is to keep the same stable line, See #4952
and see #4977 for interface related issues with jQuery


#3 @ionfish
14 years ago

  • Milestone 2.3 deleted
  • Resolution set to invalid
  • Status changed from new to closed

Thanks for the help, chaps. Looks like noConflict() mode was indeed it.

#4 @mdawaffe
14 years ago

WordPress has to use noConflict because it also uses prototype in places. Even after we switch everything to jQuery, WP will still use noConflict to give plugins the most flexibility.

You should use the jQuery object initially instead of the $ object to avoid conflicts with WP, other JS libraries and even other jQuery plugins.

jQuery(document).ready(function($) {
 // The function was called with $ as its argument so
 // inside here, $ is the jQuery object as expected.
 // Here on out, you can just use $.
} );

or just jQuery(function($) { ... } );


There's some alternative solutions here: http://docs.jquery.com/Using_jQuery_with_Other_Libraries

Note: See TracTickets for help on using tickets.