(Translation of this story from the authors of the most popular library would be very instructive for anyone who would like to keep abreast of browser tectonics in the light of the solvable problems with DOM parsing at this stage.)Much water has flowed since the last major release, and you certainly deserve updates. Therefore, we are pleased to announce the release of the first alpha version of jQuery!
Despite the version number 3.0, we expect that this release will not cause too much trouble when upgrading the code. Yes, there are several critical changes, which is justified by the change of the older index version, but we hope that these modifications will not affect many.
The jQuery Migrate plugin will help identify code compatibility issues. Also, your opinions about this alpha will help us a lot, so please try it on existing code and plugins!
')
The first release,
jQuery 3.0 , is supported by new browsers and IE 9+. The second,
jQuery Compat 3.0 , is supported in IE 8+. As a bonus, both releases will be supported by a Yandex browser released in 2012.
You can get files from jQuery CDN or direct links:
code.jquery.com/jquery-3.0.0-alpha1.jscode.jquery.com/jquery-compat-3.0.0-alpha1.jsYou can install them via
npm :
npm install jquery@3.0.0-alpha1
npm install jquery-compat@3.0.0-alpha1
Major changes
Here are discussed only the main of the new features, changes and corrections. The full list of changes is shown below and is tracked on
our GitHub account without any problems. On GitHub, in addition, you can see not yet implemented functions that are planned in later beta and final versions.
Simplified methods .show () and .hide ()
The whole point of .hide () in jQuery is to set the 'display: none' property in CSS. Accordingly, .show () will refresh the screen so that the item is displayed again (provided that its parents are not hidden). It's simple, right?
Okay, not everything. In fact, there are many difficult special cases that people have asked us to “fix” over the years, which have found themselves in a tangled tangle of principles. For example, what if an element is not set to
display: none in the style sheet? jQuery will try to determine its force setting
display: block on the element. Well, but what if the default block element <li> was set to
display: inline in another style sheet rule? What about the case when you call these methods on an element before it is added to the document, and we don't know what value the display will have? Identifying all of this creates additional work. Sometimes we are still based on assumptions, and the result is not so.
Because these methods add a style attribute to an element, they will not work well with techniques such as responsive design, where the visibility of elements may depend on media queries. This leads to the need for jQuery handlers that listen for
orientationchange or
resize events to manually hide or display portions of the page; this destroys the elegance of the decision that they tried to make through media queries.
You can see that jQuery is already halfway to total madness, and there is no point in completing the journey. Special cases and checks would not only be complex and incomplete, but would also cause significant performance problems on large pages.
Instead, we experimentally ignore the evolution of these methods and return to the simple initial model. This will break some code. If you have elements whose styles have
display: none , the
.show () method will not override this property. So the most important rule for switching to jQuery 3.0 is:
Do not use style sheets to set the default display: none , and then try to use .show () - or another method that shows the elements -
.slideDown () or
.fadeIn () - to make it visible.
If you need an element that will be hidden by default, it is better to add the class name of the type “hidden” to the element and determine that the class will be
display: none in styles. You can then add or remove this class, using the
.addClass () and
.removeClass () methods in jQuery to control visibility. In addition, you can have the
.hide () call handler on elements before they are displayed on the page. Or, if you really need to store the default styles, you can use
.css (“display”, “block”) (or another
display value) to override the styles.
We know that this will probably be one of the most controversial and complex changes in jQuery 3.0, so we wanted to put it into release as early as possible to see the effect. Please let us know how it affects your code and what needs to be changed in order to work with this new model.
github.com/jquery/jquery/issues/1767github.com/jquery/jquery/issues/2057github.com/jquery/jquery/issues/2308Special case with names in .data ()
We updated our implementation of .data () to better comply with
the HTML5 data specification . All keys are converted from kebab-case to camelCase, regardless of the access method, and the numbers no longer participate in the conversion. For example, we do not distinguish between "foo-bar" and "fooBar", but distinguish between "foo-42" and "foo42". These changes will mainly play a role when retrieving all data using a .data () call with no arguments or trying to access data using the converted .data key (“foo42”) instead of the original .data (“foo-42”).
github.com/jquery/jquery/issues/1751jQuery.Deferred is now compatible with Promises / A +
JQuery.Deferred objects have been updated for compatibility with Promises / A + and ES2015 Promises, checked
by Promises / A + Compliance Test Suite . This means the introduction of the
.catch () method and several major changes in the
.then () method:
- The exception to the .then () callback now sets the failure value. Previously, exceptions skipped everything up to the interruption of the callback and irreversibly blocked both Deferred objects — the parent and the descendant.
- The resolution state in Deferred is created by the .then () method and is now controlled by its callbacks — the exception is the deviation values, and non-thenable returns have become fully complementary values. Previously, returns from deviation handlers became deviation values.
- Callbacks are always called asynchronously. Previously, they could be called immediately after binding or resolution, depending on what came last.
- Progress callbacks can no longer resolve Deferred objects to which they are attached.
Consider the following code, in which the Deferred parent is rejected, and the child callback throws an exception:
var parent = jQuery.Deferred(); var child = parent.then( null, function() { return "bar"; }); var callback = function( state ) { return function( value ) { console.log( state, value ); throw new Error( "baz" ); }; }; var grandchildren = [ child.then( callback( "fulfilled" ), callback( "rejected" ) ), child.then( callback( "fulfilled" ), callback( "rejected" ) ) ]; parent.reject( "foo" ); console.log( "parent resolved" );
In jQuery 3.0, this will give out “parent resolved” before calling any callback, each child of the callback will return “fulfilled bar”, and the grandchildren will be rejected with the error “baz”. In previous versions, the rejected bar would be issued (the Deferred child was rejected instead of fulfilled) once, and then the execution would stop due to the unresolved baz error (parent resolved is not displayed and the grandchildren remain unfulfilled).
While caught exceptions were an advantage to debug in the browser, this is a much more declarative (that is, explicit) way to handle them with a failback callback. Keep in mind that it requires you to always add at least one such callback when working with promises. Otherwise, any errors will go unnoticed.
Old behavior can be restored by replacing
.then () with the now obsolete
.pipe () method (which has the same signature).
jQuery.when has also been updated to accept any thenable object that includes native promises.
github.com/jquery/jquery/issues/1722github.com/jquery/jquery/issues/2102Removed special states of Deferred methods in jQuery.ajax
The jqXHR object is a promise (Promise), but it has additional methods, such as .abort (), so you can stop the request after it has been made.
Since users are increasingly choosing the Promise template for asynchronous AJAX work, the idea of ​​returning special states for Promise from jQuery.ajax is not very good.
success, error, complete
done, fail, always
Please note that this does not affect all callbacks with the same name that continue to exist and are not considered obsolete. This only affects promis methods!
github.com/jquery/jquery/issues/2084Do not ignore errors
Perhaps in deep reasoning you asked the question “What is a window displacement?” Then you probably understood that it was a crazy question - how can you give a window a shift at all?
Previously, jQuery sometimes tried in such cases to return something meaningful, and not to expose errors. In this case, when requesting a window offset, the answer was {top: 0, left: 0}. In this jQuery 3.0 alpha, we experiment with the idea of ​​generating errors in such cases so as not to ignore meaningless requests. Please try alpha and see if there is any jQuery dependent code that hides problems with the wrong code.
github.com/jquery/jquery/issues/1784.width (), .height (), .css ("width"), and .css ("height") began to return fractional values ​​(if the browser allows)
Previously, jQuery returned rounded widths and heights. Some browsers return sub-pixel values ​​— such as IE and Firefox — and sometimes users need this accuracy. We do not expect this change to have a big impact on your code, but let us know if this happens.
github.com/jquery/jquery/issues/1724Removed obsolete event aliases
.load ,
.unload and
.error are deprecated since jQuery 1.8. Use .on () to register handlers.
github.com/jquery/jquery/issues/2286jQuery.swap, jQuery.buildFragment and jQuery.domManip are no longer available.
These methods have always been for internal use only and have not been documented. We finally made them private to avoid confusion.
github.com/jquery/jquery/issues/2224github.com/jquery/jquery/issues/2225Animations now use requestAnimationFrame
On platforms that support the
requestAnimationFrame API , except IE8-9, jQuery now uses this API for animation. This should give smoother animations, use less CPU time and save battery on mobile devices.
jQuery tried to implement
requestAnimationFrame a few years ago, but then there were
serious compatibility issues with existing code. We think we have solved most of these issues by pausing the animation when the browser tab is closed. However, any code that depends on the animation and runs in almost real time makes this assumption wrong.
.unwrap (selector)
Before jQuery 3.0, the .unwrap () method took no arguments. The
selector argument indicates which wrappers to remove.
github.com/jquery/jquery/issues/1744Significant acceleration for some native jQuery selectors
Thanks to some Paul Irish research work at Google, we’ve identified some cases where we could miss a lot of extra work, when the selectors like
: visible are used many times in a document. It sometimes improves speed up to 17 times!
Keep in mind that even with this improvement, selectors like
: visible and
: hidden can be expensive because they depend on the browser to determine whether elements are displayed on the page. This may require, at worst, a full CSS recalculation and page layout! We, without interfering with their use, we recommend checking the pages with such selectors for performance.
github.com/jquery/jquery/issues/2042Thanks
Many thanks to everyone who participated in testing this release, reporting bugs, or providing patches, including by name:
Chris Antaki, Jason Bedard, Leonardo Braga, Bastian Buchholz and 10+ more lines of namesChris Antaki, Jason Bedard, Leonardo Braga, Bastian Buchholz, Anne-Gaelle Colom, David Corbacho, Brenard Cubacub, Hamish Dickson, Ben Edelman, Stephen Edgar, elas7, flexphperia, Corey Frang, Xue Fuqiao, Oleg Gaidarenko, Richard Gibson, Michałyławy, elf7 , Scott González, goob, Veaceslav Grimalschi, Mu Haibao, Dan Hart, Frederic Hemberger, Nicolas Henry, Daniel Herman, Jon Hester, Victor Homyakov, Winston Howes, Daniel Husar, Essam Al Joubori, Veres Lajos, George Mauer, Richard McDaniel, Merchant, Calvin Metcalf, Dave Methvin, MightyBranch, Nazar Mokrynskyi, Matthew Mueller, Martin Naumann, Alexander O'Mara, Randson Oliveira, Gilad Peleg, James Pearce, PJ, Senya Pugach, Aditya Raghavan, Chris Rebert, Aurelio De Rosa; , Mike Sidorov, Nick Stefan, Arthur Stolyar, Timo Tijhof, Ben Toews, Thomas Tortorini, Shivaji Varma, Arthur Verschaeve, Rick Waldron, Bin Xin, Imran M Yousuf, Jörn Zaefferer.
All changes
Here is a complete list of changes since the last official releases (1.11.3 and 2.1.4).
Common to both jQuery and jQuery Compat releases
Ajax
- Always use script injection in globalEval ( # 1449 , bbdfbb4 )
- Remove JSONP callbacks using the “jQuery # removeProp” method ( # 2323 , a2ae215 )
- remove event dependency from AJAX module ( 4e7f34f )
- Correction of interrupted request in ajaxSend ( # 1775 , 598ed05 )
- use an anchor tag to parse the URL ( # 1875 , b091fdb )
- Fix cross-domain detection for non-standard port ( 83b038f )
- $ .post and $ .get can now receive options ( # 1986 , 89ce0af )
- simplify a single Ajax call and add an explanatory comment ( 0ac28ed )
- make jQuery # load field "type" explicit ( 4ef120d )
- replace “jqXHR.complete” callback with “always” ( 97ef1f2 )
- remove obsolete extensions from Ajax promise ( # 2084 , 9d1b989 )
- remove the second argument in jQuery # each ( a4715f4 )
- remove OnUnload handler ( a117dd0 )
- Remove remnants of event synonyms ( 38a6697 )
Attributes
- add a class for SVG manipulations ( # 2199 , 20aaed3 )
- return null when attribute does not exist ( # 2118 , aaeed53 )
- Use the val hook option in select val hook and simplify it ( # 1902 , f6302b0 )
- remove unnecessary checks on null ( 55ac56a )
- fix test return value to new ( 5dc4616 )
- return to null return for non-elements ( 7632b74 )
- return to null for non-existent attributes ( +2905961 )
Callbacks
Core
- Return an empty array instead of null for parseHTML ("") ( # 1997 , 4116914 )
- use document.implemenation.createHTMLDocument in jQuery.parseHTML ( 58c2460 )
- Follow AMD specifications for define ( 892625b )
- Throw an error on $ ("#"), and not return a collection of 0th length ( 80022c8 )
- allow initialization of accepting jQuery root alternative for sake flashing ( # 2101 , 7a6931d )
- remove unnecessary createHTMLDocument tests ( +5923282 )
- pass empty string to createHTMLDocument for IE ( 31c7d7f )
- return add createHTMLDocument. Thank you, Safari 8. ( b779831 )
- Update jsdom checks, discard obsolete workarounds ( # 2153 , 06f6cd1 )
- re-enter createHTMLDocument in parseHTML; Safari 8 ignored ( cfe468f )
- Standardization IndexOf Comparison ( 53aa87f )
- delete custom .ready events ( # 2264 , c252c5f )
- Consistently use a local reference to access () ( 2fb719e )
- Remove obsolete context and selector properties ( # 1908 , 0ea8c32 )
- remove isArray-like node check ( # 2238 , 436f0ae )
- add support for items with tags separated by a hyphen ( 534f130 )
- Use window.setTimeout & friends instead of global equivalents ( # 2177 , 219c749 )
- remove size () and andSelf () methods ( # 1749 , f110360 )
- remove the strundefined variable ( 29838b6 )
- Make jQuery objects iterable ( # 1693 , bb026fc )
- add bypass for iOS JIT errors in isArrayLike ( # 2145 , 1541664 )
- Check out all cases of factory use from intro.js ( # 2181 , ab40725 )
- Moving from modules to only window.setTimeout etc. ( 842958e )
- branch compatibility: remove unused variables, add comments ( f6de5a9 )
- simplify the "each" test in style iterations ( fcb6c4d )
- Simplify and speed up .each ( eeda11c )
- arrange prop & attr codes similar ( 5153b53 )
- change jQuery.each and jQuery # each ( # 2090 , 2380028 ) signatures
CSS
- CSS: Event: Simplifying Native Method Signatures ( 85577a3 )
- Fix test “sanity check” (“sanity check”, 995f707 )
- Remove non-functional unit test for negative margin ( 4ab7431 )
- Add integration test for gh-1764 ( +8887106 )
- Remove using getDefaultComputedStyle ( # 15227 , 274feb5 )
- Use predefined display for html and body ( a772418 )
- Fix typos in the comments ( 7e09619 )
- fix : visible /: hidden selectors for inline content element ( # 2227 , 79bcb29 )
- Support relative adjustment in any active unit ( # 1711 , 9b03f6d )
- elements are hidden when either offsetWidth or offsetHeight are zero ( # 10406 , # 13132 , 10399dd )
- Ignore CSS cascade in show () / hide () / etc ( # 1767 , # 2071 , 86419b1 )
- Fix test support pixelMarginRight in Android 2.3 ( cdfc2d0 )
- Clear memory leak at reliableMarginRight ( # 1795 , 7d15b4d )
- Do not cache non-standard CSS properties ( # 2015 , d471842 )
- Do not name the anonymous swap function ( 0019a46 )
- make getStyles () more readable ( 3a0d582 )
- Work on full-screen errors in IE11 ( # 1764 , 90d828b )
- Add unit test for negative margin and positioning ( 1b932bb )
- simplify the "defaultDisplay" module ( c62486f )
- Make in .css ("width") & .css ("height") return fractional values ​​( # 1724 , b60b26e )
- Do not show jQuery.swap ( # 2058 , bb4d888 )
Data
Deferred
Dimensions
- allow changing the coordinates of the argument ( # 1848 , f7e60dc )
Documents
- 1.x-master branch -> compat branch; 2.x branch -> master branch ( 758fd6c )
- correct grunt command in README.md ( # 1850 , 9d6beac )
- remove redundant instructions from readme ( # 2359 , 3c92770 )
- Refine custom build instructions ( a3779bc )
Effects
- Adding tests for jQuery.Animation ( b3b2d6c )
- Re-use requestAnimationFrame ( # 15147 , 72119e0 )
- add tests for jQuery.easing._default in Animation and Tween ( 6d7ef56 )
- set default easing in jQuery.easing._default ( # 2219 , 5f2ea40 )
- Add tests for jQuery.Tween ( cdaed15 )
- Improve raf logic ( 708764f )
Developments
- remove the preDispatch hook and simplify the signature “imitation” ( 3655c4e )
- remove guard for falsy jQuery # on argument handler method ( fac67a9 )
- remove HTML5 events inherited from MouseEvent ( # 2009 , d7e5fce )
- Completely clear events in unit testing ( 4467ed6 )
- Empty namespaces should be ignored without incident ( 8653068 )
- remove outdated originalEvent hacks ( 6df669f )
- Remove fake originalEvent from jQuery.Event.simulate ( # 2300 , 7475d5d )
- fix the error of the wrong window with scrollTop / Left in frames ( # 1945 , d21edb5 )
- remove obsolete event aliases ( # 2286 , 0705be4 )
- Add MouseEnter Chrome Error Note ( a5e1c9b )
- Restore the `constructor` property in the jQuery.Event prototype ( # 15090 , b807aed )
- Copy the detail property in jQuery.Event from native events ( # 1867 , d9ed166 )
- remove internal argument in .on () method ( 04a2969 )
- Normalize mouse event properties in drag events ( # 1925 , 97cf528 )
- detail comment focus (in | out) & rename support prop ( c074006 )
- remove redundant checks on event methods ( # 2047 , a873558 )
Manipulation (DOM)
- improve test for data-URI ( dd596cc )
- add support for items tagged with hyphens ( # 1987 , 85ffc6d )
- remove internal remove () method argument ( # 2301 , 349edbd )
- privatize the buildFragment () function ( # 2224 , a74320f )
- do not insert tbody automatically ( # 1835 , e984d1c )
- Support for inserting data-URI scripts ( # 1887 , 15f4dec )
- detect the hidden ReplaceWith input without content ( # 2204 , 4b27ae1 )
- Make an HTML interception point ( # 1747 , 225bde3 )
- increase the delay of the data-URI test ( # 1993 , 4fae911 )
- privatize the functions of the internal domManip () ( # 2225 , 62d5579 )
- simplify HTML wrappers ( # 2002 , 0ea342a )
- make wrapAll funarg executable once ( # 1843 , 359b03c )
Offset
- remove ownerDocument check to offset getter ( # 2115 , 6176567 )
- Round offsets for floating point errors ( # 2147 , 62ae2d0 )
- return zeros (zeros) for disabled / hidden items ( # 2310 , 40dcc76 )
- Fix .offset () to work correctly with ShadowDOM ( # 1784 , 1617479 )
- countdown to scroll when positioning ( # 1708 , 2d71594 )
- Do not run the IFRAME scrollTop / scrollLeft test in Android 2.3 and 4.0 ( # 1981 , 0c46643 )
- getBoundingClientRect , IE8-11 ( 0e4477c )
- + ( b041242 )
- jQuery#offsetParent ( 74ae544 )
Selector/Sizzle
Wrap
, : Readme, Build, Test, ...miscellanea
«Readme»
Build
- Sizzle 2.0.0 ( bcca4f0 )
- grunt-contrib-jshint ( 1556c46 )
- bower.json lint target ( 285cfbf )
- mailmap ( 3ec73ef )
- ( # 2331 , 8e92e1e )
- bower; npm front-end ( # 15186 , e1949f4 )
- front-end ( 8356948 )
- node dependencies barring jscs ( 8e3a0ce )
- grunt-jscs-checker ( c869a1e )
- requirejs 2.1.17 ( # 2290 , a644101 )
- source map grunt jshint ( 269a27c )
- bower.json: `version` ( 61e21a4 )
- assertions, QUnit ( 8b6aeae )
- commitplease dev ( 39b7606 )
- JSHint ( 34da7d5 )
- authors.txt ( 8f13997 )
- 2.0.0 ( 5bc1ddc )
- QUnit (1.17.1) ( 2d5c5d2 )
- 3.0.0-pre ( 7a607c5 )
- ( fbdbb6f )
- Fix ( dc4b914 )
- Travis ( 31f4f8e )
- define({}) ( # 1768 , 2c1b556 )
- npm ( b92acf7 )
- grunt-bowercopy 1.0.0 ( 323e82c )
- Sizzle ( 8d11310 )
- AMD ( +6051609 )
- ( c5d9d88 )
- version labels in Sizzle versions ( # 1939 , 78ac753 )
- node dependencies ( +9101704 )
- Sizzle ( d6c97ab )
- browser environment; smoke test on Node w/ jsdom ( # 1950 , 76df9e4 )
- ( 66e1b6b )
- ( 0c9d018 )
- npm install ( 35f8e15 )
- Sizzle 1.11.1 ( c0b23e2 )
- Sizzle ( # 2042 , # 1969 , 3a0dd5a )
- grunt-bowercopy ( 712e78c )
- ( 4f776e5 )
- Sanctify the component name status of Wrap ( a4133ff )
- native-promise-only () ( f5aa89a )
- grunt/npm build/dist/test ( bb928bd )
- native-promise-only ( 0065e1f )
- sinon ( # 2160 , 98c25b7 )
Release
Support
Tests
jQuery 3.0
Ajax
CSS
Data
Offset
, : , Readme, Build, Testsmiscellanea
Documents
«Readme»
- selector-native.js . randsonjs! ( cfe2eae )
Build
Tests
jQuery Compat 3.0
Ajax
Attributes
CSS
Data
Deferred
Effects
Developments
DOM
Offset
Traversing
, : , Build,Documents
Build
miscellanea
Tests
- IE8 (Sinon IE HTML5 Shiv) ( 0b07c65 )