Bug Tracker

Opened 10 years ago

Closed 10 years ago

#9977 closed bug (invalid)

.data() does not return DOM object for method chaining in IE8 and below

Reported by: [email protected] Owned by: [email protected]
Priority: low Milestone: None
Component: data Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:

Description

I don't know if this is a bug in jQuery or a bug in the library that I was debugging (I don't know which behavior is correct) but I'm still going to raise it. The following code works in all browsers except IE <= 8. (It functions in IE9, I checked.):

var header = $("<div class='ui-state-default slick-header-column' id='" + uid + m.id + "' />")
.html("<span class='slick-column-name'>" + m.name + "</span>")
.width((m.currentWidth || m.width) - headerColumnWidthDiff)
.attr("title", m.toolTip || m.name || "")
data("fieldId", m.id)
.appendTo($headers);

This code fails in IE8 with an error stating that ....data(...) is null or not an object. In every other browser (Firefox, Chrome, Safari and Opera tested), data() seems to return the dom object and allows .appendTo() to be called. Either way, I was able to fix this by changing the code to the following:

var header = $("<div class='ui-state-default slick-header-column' id='" + uid + m.id + "' />")
.html("<span class='slick-column-name'>" + m.name + "</span>")
.width((m.currentWidth || m.width) - headerColumnWidthDiff)
.attr("title", m.toolTip || m.name || "")
.appendTo($headers);

header.data("fieldId", m.id);

This works as intended in all browsers.

It occurs to me that the behavior of data might be undefined if it is called on an object that has not yet been inserted into the DOM. If this is not actually a bug but a misfeature that the library relied on, then I apologize. Still, I figured I'd let you know.

Change History (3)

comment:1 Changed 10 years ago by Rick Waldron

Component: unfileddata
Owner: set to [email protected]
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 10 years ago by [email protected]

Status: pendingnew

I'm unable to reproduce this as a standalone bug. My apologies, it must be something elsewhere in this mess of code I've inherited.

comment:3 Changed 10 years ago by Rick Waldron

Priority: undecidedlow
Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.