#11221 closed bug (invalid)
jQuery.data and jQuery.fn.data not working
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | data | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
jQuery.data and jQuery.fn.data functions running on Firefox 9.0.1 of MacOSX are not returning the correct value.
jQuery.data(obj) returns the cache element with events, data, handle and parsedAttrs, not only data of cache.
Change History (13)
comment:1 Changed 11 years ago by
Component: | unfiled → data |
---|---|
Owner: | set to [email protected]… |
Priority: | undecided → low |
Status: | new → pending |
comment:2 follow-up: 3 Changed 11 years ago by
Status: | pending → new |
---|
In jsFiddle seems to be working, but if you run the code snippet on console directly on http://jqueryui.com (which is being used version 1.7.1 of jquery) the error will occur:
var div = $ ('div: first'); $. date (div, 'test', 'test');
console.log ($. date (div));
Any other site with or without jQuery UI occurs that error (just with version 1.7.1 of jquery). So jQuery UI not is the cause of problem.
Note: This error only occurs in Firefox MacOSX (the version used was 9.0.1).
Note 2: This is not an error, just an incorrect result of jQuery.data function.
comment:3 Changed 11 years ago by
Status: | new → pending |
---|
var div = $ ('div: first'); $. date (div, 'test', 'test');
console.log ($. date (div));
Do you mean $.data()? Why are you using the static $.data method?
Try...
console.log( $("div: first").data("test", "test").data() );
comment:5 Changed 11 years ago by
Status: | new → pending |
---|
Ok, so we ask once again, can you please provide a reduced test case with jsfiddle? Thanks
comment:6 Changed 11 years ago by
Status: | pending → new |
---|
My test was here http://jsfiddle.net/CvGjj/1/ But in jsfiddle do not occurs that error. If you run it directly on firebug the result is diferent.
I copy exactly the html returned by jsfiddle (inserting the firebug lite) and in lite the result was equal to the jsfiddle, but in native firebug the result was diferent (with exactly the same javascript code).
comment:7 Changed 11 years ago by
Again, I ask.. what is the "ERROR"? The toJSON property? Why are you using the static $.data() method?? Use $(div).data()
comment:8 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
The test case is invalid. $.data cannot be passed a jQuery object, only an element.
http://api.jquery.com/jQuery.data http://api.jquery.com/data
It may help to ask for support on the forums or on the #jquery irc channel.
comment:9 Changed 11 years ago by
You may consider this invalid, but have a bug, only in this version of jquery (any oldest version haven't this bug) and only on this browser (in chrome and safari it work fine).
Both $.data or $.fn.data results the same bug. The return on that case are not object with data values, but a top level of this object, containing data, event handlers, etc. It is no a problem to worry about, but this bug exists.
comment:10 Changed 11 years ago by
I'm having the same issue on FF 10.0.2 and 11.0 on OS X. In jsfiddle everything works, but your own code it fails. Try this in your console:
var $div = $('<div></div>'); $div.data('a','1'); console.log( $div.data('a') );
'undefined'
It's undefined because $div.data() actually returns the the top-level object of data. To get the expected behavior you have to go one-level deep, so both of these work:
var $div = $('<div></div>'); $div.data('a','1'); console.log( $div.data('data.a') ); var $div = $('<div></div>'); $div.data('a','1'); console.log( $div.data().data.a );
Notice that you have to get the 'data' property of the returned object from data().
comment:11 Changed 11 years ago by
Never mind, the problem isn't with jQuery it's with FireQuery 1.1. If you disable that extension, data() works as expected.
comment:12 Changed 11 years ago by
F.Y.I. I am having the same problem. Using IE9. I have had to rewrite my code to stop using jquery.data and to attach the data directly to the dom elements instead. Problem was not present in earlier versions of jquery. The problem occurs sporadically which makes it uneasy to reproduce.
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!
Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.