You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jQuery has provided the .data() method since 1.4, and in 1.6 there was a change that made it conform to the HTML5 data specification. According to the specification, the key nested-single should be converted into nestedSingle, and nested--double should be converted into nested-Double.
The .data() method allows for no arguments to be provided, which the docs says should return all of the values as an object
Calling .data() with no parameters retrieves all of the values as a JavaScript object.
In jQuery 2.x, this works correctly and $(element).data() matches element.dataset as one would expect.
In jQuery 1.x, data attributes with two consecutive dashes (--) are converted the same way as data attributes containing a single dash. This means that nested-single and nested--single are treated in the same way, both being converted to nestedSingle.
Special notes
In 1.6 through 1.6.3, attributes containing two dashes in a row are not included in the returned object. This appeared to be fixed in 8e8fa6d, which makes 1.6.4 the first version where this bug appears in 1.x.
As we have established already, jQuery 1.x does not correctly handle
`data-*` attributes where there are multiple dashes. This makes it
so we can still handle nested options when working with jQuery 1.x
by using the `.dataset` option that is supported by all major
browsers as well as IE 11+.
Browser support tables for the `.dataset` attributes can be found at
http://caniuse.com/dataset
A notice was already added to the documentation about this in
caeb0ec.
The related ticket in the jQuery repository about this issue is
jquery/jquery#2070.
This closes#2969.
jQuery has provided the
.data()
method since 1.4, and in 1.6 there was a change that made it conform to the HTML5 data specification. According to the specification, the keynested-single
should be converted intonestedSingle
, andnested--double
should be converted intonested-Double
.The
.data()
method allows for no arguments to be provided, which the docs says should return all of the values as an objectIn jQuery 2.x, this works correctly and
$(element).data()
matcheselement.dataset
as one would expect.In jQuery 1.x, data attributes with two consecutive dashes (
--
) are converted the same way as data attributes containing a single dash. This means thatnested-single
andnested--single
are treated in the same way, both being converted tonestedSingle
.Special notes
In 1.6 through 1.6.3, attributes containing two dashes in a row are not included in the returned object. This appeared to be fixed in 8e8fa6d, which makes 1.6.4 the first version where this bug appears in 1.x.
Tests
HTML code used for testing
jQuery
.data
testThis will pass in 2.x, but fail in 1.x.
HTML5
dataset
testThis passes, as expected.
/refs select2/select2#2969
/cc @loic
The text was updated successfully, but these errors were encountered: