With the major version of 3.0, the jQuery Core team has taken the opportunity to make changes to clean up the API and fix bugs that may prove to be breaking changes for some code. This includes the removal of previously deprecated public APIs, changes to or removal of undocumented APIs, and changes to the documented or undocumented behavior of existing APIs for specific inputs.
As of jQuery 3.0, the following browsers are supported:
jQuery team policy is to only change browser support on major-version updates, so this list will apply until at least jQuery 4 arrives.
As with the major changes made in jQuery 1.9/2.0, we have created a new version of thejQuery Migrate Plugin to simplify migration of older code to version 3.0. We strongly recommend that you use this plugin as an upgrading tool, it will give specific advice about most of the major changes that may affect your code.
Version 3.0 of the jQuery Migrate Plugindoes not warn about or restore behaviors that were removed in previous major version changes such as jQuery 1.9/2.0. Use the following steps to upgrade from a version of jQuery older than 1.11.0 or 2.1.0 to this new version 3.0:
Running both Migrate 1.x and Migrate 3.x simultaneously on the same page is not supported.
The uncompressed development version of the Migrate plugin includes console log output to warn when specific deprecated and/or removed features are being used. This makes it valuable as a migration debugging tool for finding and remediating issues in existing jQuery code and plugins.
The compressed version of the Migrate plugin does not generate any warnings, although it does issue a solitary console message that it has been installed to simplify debugging. Migrate can be used on production sites when jQuery 3.0 or higher is desired but older incompatible jQuery code or plugins must also be used. Ideally this is only used as a short-term solution, since restoring old behavior may cause conflicts with new jQuery code that expects the new behavior.
With a library as widely used as jQuery, it is often difficult for the team to know which changes may impact developers the most before a release occurs. Despite the length of this list, we believe that the majority are edge cases. Many jQuery projects should be able to run version 3.0 with only minor changes if any.
Changes are listed by their component category, and prefixed with a description to help you understand its impact:
Remember that the jQuery Migrate plugin described above can detect and warn about many of these changes so that they can be fixed in your code.
For a complete and detailed list of all code changes, see the 3.0 milestone in thejQuery Core issue tracker or theversion diff.
ThejqXHR object returned fromjQuery.ajax() is a jQueryDeferred and has historically had three extra methods with names matching the arguments object ofsuccess,error, andcomplete. This often confused people who did not realize that the returned object should be treated like aDeferred. As of jQuery 3.0 these methods have been removed. As replacements, use theDeferred standard methods ofdone,fail, andalways, or use the newthen andcatch methods for Promises/A+ compliance.
Note that this does not have any impact at all on the ajax callbacks of the same name passed through theoptions object, which continue to exist and are not deprecated. This only affects the jqXHR methods.
https://github.com/jquery/jquery/issues/2084
When making a request viajQuery.ajax() orjQuery.get() for a script on a domain other than the one that hosts the document, you must now explicitly specifydataType: "script" in the options. This prevents the possibility of an attack where the remote site delivers non-script content but later decides to serve a script that has malicious intent. SincejQuery.getScript() explicitly setsdataType: "script" it is unaffected by this change.
jQuery.ajax() callThejQuery.ajax() method no longer strips off the hash in the URL if it is provided, and sends the full URL to the transport (xhr, script, jsonp, or custom transport). If the server at the other end of the connection cannot deal with a hash on a URL, strip it off before sending the request.
https://github.com/jquery/jquery/issues/1732
jQuery 3 adds a new signature for thejQuery.get() and thejQuery.post() functions by adding asettings parameter. It's an object that can possess many properties and its the same object that you can provide tojQuery.ajax().
https://github.com/jquery/jquery/issues/1986
.removeAttr() no longer sets properties to falsePrior to jQuery 3.0, using.removeAttr() on a boolean attribute such aschecked,selected, orreadonly would also set the corresponding namedproperty tofalse. This behavior was required for ancient versions of Internet Explorer but is not correct for modern browsers because the attribute represents the initial value and the property represents the current (dynamic) value.
It is almost always a mistake to use.removeAttr( "checked" ) on a DOM element. The only time it might be useful is if the DOM is later going to be serialized back to an HTML string. In all other cases,.prop( "checked", false ) should be used instead.
https://github.com/jquery/jquery/issues/1759
https://github.com/jquery/jquery/issues/2913
Before jQuery 3.0, calling.val() on a<select multiple> element with no elements selected returnednull. This was inconvenient since if at least one value was selected the return value would be an array. Also, if all options are disabled jQuery already returned an empty array. To improve consistency, the nothing-selected case now returns an empty array.
https://github.com/jquery/jquery/issues/2562
SVG has never been fully supported by jQuery and this hasn't changed in jQuery 3. Nonetheless, many jQuery methods work with SVG documents as well. As of jQuery 3 the methods that manipulate class names, such as.addClass() and.hasClass(), support SVG.
https://github.com/jquery/jquery/issues/2199
.toggleClass() with no arguments and.toggleClass( Boolean )Although a signature for these two cases was documented, its actual behavior was never fully defined. This undefined behavior is now deprecated so it will not be documented. You may find you were accidentally using the functionality because.toggleClass( undefined ) behaves the same as a call with no arguments, even though it was invalid input.
If a Callback object has a handler function that calls the.lock() method after being.fire()d, it only prevents future execution of the callback list and does not immediately abort execution of the current list. To stop the current execution, use thestopOnFalse option.
https://github.com/jquery/jquery/issues/1990
Now that most of the browsers supported by jQuery 3.0 have"use strict", jQuery is being built with this directive. Your code is not required to run in Strict Mode, so most existing code should not require any changes. The one case we encountered three years ago was that ASP.NET 4.0 usedarguments.caller.callee to attempt tracing through call stacks in its__doPostBack() method. If you are still using a version of ASP.NET that still does this, keep using jQuery 2.x or earlier. Modern browsers support stack traces viaerror.stack so it should not ever be necessary to examinearguments.caller.callee.
https://github.com/jquery/jquery/pull/3061
https://bugs.jquery.com/ticket/13335
The document-ready processing in jQuery has been powered by thejQuery.Deferred implementation since jQuery 1.6. As part of jQuery 3.0's alignment with the Promises/A+ standard, document-ready handlers are called asynchronously even if the document is currently ready at the point where the handler is added. This provides a consistent code execution order that is independent of whether the document is ready or not. For example, consider this code:
1 2 3 4 |
|
In jQuery 3.0 this will always log "outside ready" followed by "ready" regardless of whether the document is ready at the point of execution. Earlier versions may log the messages in either order.
Since handlers now execute independently of each other, an exception or failure in one document-ready handler no longer prevents other document-ready handlers from running.
In custom builds where thedeferred module is excluded, an alternative implementation of the document-ready code is used. This implementation supports thejQuery.ready promise but is not ajQuery.Deferred object so it should only be used throughjQuery.when().
https://github.com/jquery/jquery/issues/1823
https://github.com/jquery/jquery/pull/2891
.toString()ThejQuery.isNumeric() method is intended to be used with primitive numbers and strings that can be coerced to finite numbers. In particular, it no longer tries to obtain numbers from objects that have a.toString() method. Users needing specialized checks for other numerics should create their own validation functions.
https://github.com/jquery/jquery/issues/2662
.context and.selector properties removedThese properties were deprecated in jQuery 1.9, as they were only used for the obsolete.live() method and have never accurately represented the context or selector for the current collection.
https://github.com/jquery/jquery/issues/1908
.size() removed.size() is deprecated as of jQuery 1.8 and removed in jQuery 3.0 in favor of the.length property.
Version 3.0 removes several methods from view that were intended to be private and were never documented:
https://github.com/jquery/jquery/issues/2224
https://github.com/jquery/jquery/issues/2225
undefinedWith few exceptions, any value-returning jQuery methods should returnundefined on an empty jQuery collection in keeping with ourAPI guidelines. The following APIs were changed to conform to this rule:
.width(),.height(),.innerWidth(),.innerHeight(),.outerWidth(), and.outerHeight().offsetTop() and.offsetLeft()Previously, these methods returnednull instead ofundefined for an empty collection.
https://github.com/jquery/jquery/issues/2319
for...of loops can be used on jQuery collectionsjQuery 3.0 supports thefor...of loop introduced in ES2015. It allows looping over iterable objects includingArray,Map, andSet. When using this loop, the value obtained is a DOM element of the jQuery collection, one at a time. Note that you will need to be using an environment that supports ES2015 or a transpiler such as Babel to usefor...of. Here is an example:
1 2 3 4 5 6 7 8 9 10 11 |
|
https://github.com/jquery/jquery/issues/1693
jQuery.ready promise is formally supportedjQuery.ready has been consumable as a promise-like object ("thenable" in Promise terms) since jQuery version 1.8. As of jQuery 3.0 this object is documented as supported viajQuery.when or the nativePromise.resolve(). No code should make assumptions about whether this object is a jQueryDeferred or some other type of promise object such as a native Promise. Typical usage might look like this:
1 2 3 4 5 |
|
https://github.com/jquery/api.jquery.com/pull/530
jQuery.unique(), renamed tojQuery.uniqueSort()ThejQuery.unique() method has been renamed tojQuery.uniqueSort() to make its behavior easier to understand. There is no change to functionality here, only a rename.
jQuery.parseJSON()Since all the browsers supported by jQuery 3.0 support the nativeJSON.parse() method, we are deprecatingjQuery.parseJSON().
https://github.com/jquery/jquery/issues/2800
jQuery( function )Due to historical compatibility issues there are a multitude of ways to set a document ready handler. All of the following are equivalent and call the functionfn when the document is ready:
1 2 3 4 |
|
As of jQuery 3.0 the recommended way to add a ready handler is the first method,$(fn). As noted in the Event section, the$( document ).on( "ready", fn ) event form has slightly different semantics and was removed in jQuery 3.0.
As of jQuery 3.0, all data names are stored in jQuery's internal data object in camelCase (e.g.,clickCount), rather than kebab-case (e.g.click-count). This is consistent with the way that standard DOM turns dashed names into camel case for JavaScript names in CSS and data properties.
In general, kebab case still works in jQuery 3.0 when setting or getting a specific data item, e.g..data( "right-aligned" ), but if you retrieve the internal data object it will now have the data item in camel case (rightAligned). The main difference in 3.0 is when you use kebab case names directly on the data object instead of using the.data() API to get or set them.
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
https://github.com/jquery/jquery/issues/2070
https://github.com/jquery/jquery/issues/2257
https://github.com/jquery/jquery/issues/1751
Deferreds have been updated for compatibility with Promises/A+ and ES2015 (a.k.a ES6) Promise, a change with significant consequences.
https://github.com/jquery/jquery/issues/1722
https://github.com/jquery/jquery/issues/2102
.resolve,.reject, and.notify now setundefined context instead of using the promise of the Deferred object with which they are associated. To set an explicit context, use.resolveWith,.rejectWith, and.notifyWith.
https://github.com/jquery/jquery/issues/3060
Major changes have been made to the.then() method. In particular, any exception thrown within a.then() callback is now caught and converted into a rejection value, and any non-thenable value returned from arejection handler becomes a fulfillment value. Westrongly recommend that you add a.catch() method (new in 3.0) to the end of your promise chain to avoid difficult debugging issues. The most likely place you may encounter this new behavior is when using the Deferreds that are produced byjQuery.ajax(), since thejQXHR object returned is a superset ofjQuery.Deferred.
In jQuery 1.x and 2.x, an uncaught exception inside a callback function halts code execution. The thrown exception bubbles up until it is caught inside a try/catch or reacheswindow and triggerswindow.onerror.
For example, consider this code using the new standard Promises/A+ behavior:
1 2 3 4 5 6 7 8 9 10 |
|
Compare that to the old-style Deferred methods:
1 2 3 4 5 6 7 8 9 |
|
Note that jQuery logs a message to the console when it is inside a Deferred and a JavaScript exception occurs. These messages take the formjQuery.Deferred exception: (error message). If you do not want any console output on these exceptions, setjQuery.Deferred.exceptionHook toundefined. If you need further help in finding errors reported this way, use thejquery-deferred-reporter plugin during development to obtain stack traces.
https://github.com/jquery/jquery/issues/2736
The Promises/A+ spec says that promises are always resolved with asingle value and handlers are invoked without athis context, while jQuery Deferreds sometimes pass context and/or multiple values to their handlers. In most cases, though, the first argument is the most important of these values. If you mix other Promises/A+ implementations with jQuery's, you may only receive a single argument in your handler. To maintain full compatibility for existing code, use only jQuery Deferreds and switch to the older.done() and.fail() methods which retain all the backward-compatible behavior:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Another behavior change required for Promises/A+ compliance is that Deferred.then() callbacks arealways called asynchronously. Previously, if a.then() callback was added to a Deferred that was already resolved or rejected, the callback would run immediately and synchronously.
Deferred methods such as.done(),.fail(), and.pipe() retain their old behavior and so are not Promises/A+ compliant. If you require synchronous resolution, do not want exceptions converted to rejection values or rejection callback returns converted to fulfillment values, or want thrown errors to bubble out of the function where they occur, you can use these methods instead of.then() and.catch().
jQuery.when now interprets any input argument with athen method as a Promise-compatible "thenable". This allows a much broader range of inputs, including native ES6 Promises and Bluebird promises.
Further, a more clear distinction is now recognized between multi-argument calls tojQuery.when and single- or no-argument calls.Multi-argument calls behave similarly toPromise.all, aggregating fulfillment values into a fulfillment array (with jQuery-specific enhancements of also aggregating fulfillment contexts and supporting multi-valued fulfillments), or alternatively rejecting with the first rejection value.Single- and no-argument calls behave similarly toPromise.resolve, returning a Deferred that resolves identically to thenable or Promise-like input, or fulfills with its non-Promise input (as appropriate).As of jQuery 3.0, both of these return a new Deferred (previous versions did not create a new Deferred when called with a single Deferred input).
https://github.com/jquery/jquery/issues/2018
https://github.com/jquery/jquery/issues/2546
https://github.com/jquery/jquery/issues/3029
As of jQuery 3.0, thejQuery.when() method no longer passes along progress notifications from input Deferreds to the output Deferred. Progress messages are not part of the Promises/A+ specification, and the behavior of progress notifications injQuery.when() were not previously documented in the jQuery API.
https://github.com/jquery/jquery/issues/2710
Before version 3.0, jQuery used the DOMoffsetWidth andoffsetHeight properties to determine the dimensions of an element, and these properties always return integers. With jQuery 3.0 we get more precise values via the DOMgetBoundingClientRect API, and these may not be integers. If your code always expects integers for dimensions, it may need to be adjusted to deal with this extra precision.
https://github.com/jquery/jquery/issues/1724
.outerWidth() or.outerHeight() onwindow includes scrollbar width/heightCalls to$(window).width() return the "content width" which excludes any scrollbars that the browser has added if the content exceeds the height of the element. This is different from the width that CSS uses for media queries, which includes the width of the scrollbars. In order to provide a measure that is equivalent to the CSS media query concept of width, the$(window).outerWidth() method now returns the width including scrollbar width. This is equivalent to the DOM propertywindow.innerWidth. The same applies for.outerHeight().
https://github.com/jquery/jquery/issues/1729
The code that jQuery uses to show and hide elements has been updated to focus on inline rather than computed styles, respecting stylesheetdisplay values whenever possible for increased compatibility with responsive design techniques (in which active stylesheet rules can dynamically change upon device reorientation/window resize/etc.). As a result, disconnected elements are no longer considered hidden unless they have inlinedisplay: none, and therefore.toggle() will no longer differentiate them from connected elements as of jQuery 3.0.
Further, while.show() and similar calls will continue to force visibility of elements that are hidden by stylesheet rules, supporting this functionality slows down all show/hide operations and its use is not recommended. The determination of which display value to set in such cases has also been simplified, defaulting to "block" when body-level rules hide elements by type.
Any code expecting hidden elements to be reshown with their previouscomputed display styles, or disconnected elements to treated as hidden, should be reviewed. The team created atable of all the possibilities related to the display state and show/hide actions in order to minimize the setting of non-empty inline styles.
On platforms that support therequestAnimationFrame API, which is pretty much everywhere but IE9, jQuery will now use that API when performing animations. This should result in animations that are smoother and use less CPU time—and save battery as well on mobile devices.
jQuery tried using requestAnimationFrame a few years back but there were serious compatibility issues with existing code so we had to back it out. We think we’ve beaten most of those issues by suspending animations while a browser tab is out of view. Still, any code that depends on animations to always run in nearly real-time is making an unrealistic assumption.
Now thatrequestAnimationFrame is being used for animations, thejQuery.fx.interval property is ignored on most browsers. It is still present in jQuery 3.0 and used in browsers such as IE9, but will be removed in a future major-point release.
The easing functions called by.animate() are passed single argument, the percentage of completion. Some older code assumes that it is passed additional arguments derived from the percentage. These other arguments may not be present in a future major version update.
Example of an old easing method:
1 2 3 |
|
The same easing method rewritten:
1 2 3 |
|
https://github.com/jquery/api.jquery.com/issues/912
These methods are shortcuts for event operations, but had several API limitations. The event.load() method conflicted with the ajax.load() method. The.error() method could not be used withwindow.onerror because of the way the DOM method is defined. If you need to attach events by these names, use the.on() method, e.g. change$( "img" ).load( fn ) to$( "img" ).on( "load", fn ).
https://github.com/jquery/jquery/issues/2286
.on( "ready", fn ) removedjQuery no longer supports a synthetic event named"ready" that can be used with the event functions. This event was error-prone and deprecated in jQuery 1.8 because it would only call the callback if it was attached before the document was ready. Replace any uses with$(fn) instead, which works reliably.
https://github.com/jquery/jquery/issues/2264
event.pageX andevent.pageY normalization removedAll the browsers officially supported by jQuery 3.0 provide the pageX and pageY properties in their events, so the jQuery code to calculate these values from other event properties has been removed. This change should not affect mainstream browsers, but there may be obscure environments where these properties are not present. If you find one, please open a ticket.
https://github.com/jquery/jquery/issues/3092
jQuery.event.props andjQuery.event.fixHooks removedjQuery's event handling performance increased thanks to a reorganization of event property management. The main improvement is that jQuery now only calculates or copies a property on the first access, rather than calculating and copying them up front. This is a really big win with properties that may force layout that the event handler may not even need. The most common use we know of was to add properties for pointer events, which is no longer necessary because those events are supported already in jQuery 3.0. The jQuery Migrate plugin provides support for these properties if you still need them. The related but undocumentedmouseHooks andkeyHooks lists were removed as well. The team is interested in understanding other use cases before defining new APIs, so feel free to open a ticket.
https://github.com/jquery/jquery/issues/3103
https://github.com/jquery/jquery/issues/1746
https://learn.jquery.com/events/event-extensions/
Before jQuery 3.0, the selector used in a delegated event wasn't used until the first time that event occurred on the element. This sometimes led to hard-to-debug cases where the error was far removed from the time and code where the mistake was made. Now the selector is tested when the event is attached and throws an error if it is not valid. The only reason this is considered a breaking change is that code might use an invalid selector when attaching an event that never occurs, and that case previously would have never thrown an error.
https://github.com/jquery/jquery/issues/3071
Five years ago in jQuery 1.7 we introduced the.on() method for attaching event handlers. The older.bind(),.unbind(),.delegate() and.undelegate() methods are being deprecated as of 3.0, but are still present. The API documentation explains how to rewrite the calls using the.on() and.off() methods.
.wrapAll( function ) only calls the function onceIn previous versions, the.wrapAll() method acted like.wrap() when a function was passed. This has been corrected; now and.wrapAll( function ) calls its function once, using the string result of the function call to wrap the entire collection.
https://github.com/jquery/jquery/issues/1843
.offset() methodWhen using the.offset() method, the first item in the jQuery collection must be a DOM element that has a DOMgetBoundingClientRect() method. (All browsers supported by jQuery 3.0 have this API.) Any other input may result in jQuery throwing an error. Also note that the element must be visible and currently in a document (i.e., not disconnected).
https://github.com/jquery/jquery/issues/2115
https://github.com/jquery/jquery/issues/2114
:hidden and:visibleAn element is considered now visible if it has a layout box returned from the DOMgetClientRects() method, even if that box has a height and/or width of zero. This means that elements such as<br /> or an empty<span> element that don't have height are considered to be visible.
https://github.com/jquery/jquery/issues/2227
https://github.com/jquery/jquery/issues/2604
jQuery( "#" ) and.find( "#" ) are invalid syntaxjQuery 3.0 throws a syntax error if a selector string consists of nothing but a hash-mark. In previous versions,$("#") returned an empty collection and.find( "#" ) threw an error.
https://github.com/jquery/jquery/pull/1682
jQuery.escapeSelector()The newjQuery.escapeSelector( selector ) method takes a selector string and escapes any character that has a special meaning in a CSS selector. It is essentially a shim for theCSS Working Group'sCSS.escape() method that runs on all of jQuery's supported browsers. This method is useful for situations where a class name or an ID contains characters that have a special meaning in CSS, such as the dot or the semicolon.
For example, if an element on the page has an id of "abc.def" it cannot be selected with$( "#abc.def" ) because the selector is parsed as "an element with id 'abc' that also has a class 'def'. However, itcan be selected with$( "#" + $.escapeSelector( "abc.def" ) ).
https://github.com/jquery/jquery/issues/1761
jQuery.expr[":"] andjQuery.expr.filtersThese two names for defining custom selectors through jQuery's Sizzle selection engine are the same asjQuery.expr.pseudos, so we are deprecating the redundant names.
In forms that are POST-ed viajQuery.ajax(), thespecification forapplication/x-www-form-urlencoded encoding says that any occurrence of a space should be converted to the+ character. Previously, jQuery implemented this by doing the conversion injQuery.param(). Now, that conversion has been moved intojQuery.ajax(). Data encoded viajQuery.param() will convert spaces to%20, which makes it directly compatible with the use of the native JavaScriptencodeURIComponent() anddecodeURIComponent() methods.
https://github.com/jquery/jquery/issues/2658
.andSelf() removed, use.addBack()The.andSelf() method was deprecated in jQuery 1.8 and now removed in 3.0 in favor of the.addBack() method, which does a better job of explaining what it does and also accepts an optional selector to filter what is added back.