Skip to main content

Bug Tracker

Side navigation

#11221 closed bug (invalid)

Opened January 25, 2012 12:40PM UTC

Closed January 26, 2012 10:57PM UTC

Last modified April 17, 2012 06:49PM UTC

jQuery.data and jQuery.fn.data not working

Reported by: coisa.cs@gmail.com Owned by: coisa.cs@gmail.com
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.

Attachments (0)
Change History (13)

Changed January 25, 2012 02:56PM UTC by addyosmani comment:1

component: unfileddata
owner: → coisa.cs@gmail.com
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.

Changed January 25, 2012 04:27PM UTC by coisa.cs@gmail.com comment:2

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.

Changed January 25, 2012 05:31PM UTC by rwaldron comment:3

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?

Try...


console.log(
  $("div: first").data("test", "test").data()
);

Changed January 25, 2012 05:33PM UTC by coisa.cs@gmail.com comment:4

status: pendingnew

Same result

Changed January 25, 2012 05:41PM UTC by rwaldron comment:5

status: newpending

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

Changed January 26, 2012 08:40PM UTC by coisa.cs@gmail.com comment:6

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).

[[Image(http://www.felipeabreu.com.br/depot/jquery_data_error.jpg)]]

Changed January 26, 2012 09:10PM UTC by rwaldron comment:7

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

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

Changed January 26, 2012 10:57PM UTC by timmywil comment:8

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.

Changed January 26, 2012 11:16PM UTC by coisa.cs@gmail.com comment:9

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.

Changed March 13, 2012 12:43AM UTC by zertosh@gmai.com comment:10

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().

Changed March 13, 2012 01:05AM UTC by zertosh@gmail.com comment:11

Never mind, the problem isn't with jQuery it's with FireQuery 1.1. If you disable that extension, data() works as expected.

Changed March 28, 2012 10:46AM UTC by anonymous comment:12

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.

Changed April 17, 2012 06:49PM UTC by anonymous comment:13

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