Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#11221 closed bug (invalid)

jQuery.data and jQuery.fn.data not working

Reported by: coisa.cs@… Owned by: coisa.cs@…
Priority: low Milestone: None
Component: data Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


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 6 years ago by addyosmani

Component: unfileddata
Owner: set to coisa.cs@…
Priority: undecidedlow
Status: newpending

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.

comment:2 Changed 6 years ago by coisa.cs@…

Status: pendingnew

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 in reply to:  2 Changed 6 years ago by Rick Waldron

Status: newpending

var div = $ ('div: first'); $. date (div, 'test', 'test');

console.log ($. date (div));

Do you mean $.data()? Why are you using the static $.data method?


  $("div: first").data("test", "test").data()

comment:4 Changed 6 years ago by coisa.cs@…

Status: pendingnew

Same result

comment:5 Changed 6 years ago by Rick Waldron

Status: newpending

Ok, so we ask once again, can you please provide a reduced test case with jsfiddle? Thanks

comment:6 Changed 6 years ago by coisa.cs@…

Status: pendingnew

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 6 years ago by Rick Waldron

Again, I ask.. what is the "ERROR"? The toJSON property? Why are you using the static jQuery.data() method?? Use $(div).data()

Version 0, edited 6 years ago by Rick Waldron (next)

comment:8 Changed 6 years ago by timmywil

Resolution: invalid
Status: newclosed

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 6 years ago by coisa.cs@…

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 6 years ago by zertosh@…

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') );


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 6 years ago by zertosh@…

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 6 years ago by anonymous

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.

comment:13 Changed 6 years ago by anonymous

fixed in FireQuery 1.2, I'm sorry for the troubles

Note: See TracTickets for help on using tickets.