Bug Tracker

Ticket #9977 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

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

Reported by: thegamefreak0134@… Owned by: thegamefreak0134@…
Priority: low Milestone: None
Component: data Version: 1.6.2
Keywords: Cc:
Blocking: Blocked by:

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

comment:1 Changed 3 years ago by rwaldron

  • Owner set to thegamefreak0134@…
  • Status changed from new to pending
  • Component changed from unfiled to data

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 3 years ago by thegamefreak0134@…

  • Status changed from pending to new

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 3 years ago by rwaldron

  • Priority changed from undecided to low
  • Status changed from new to closed
  • Resolution set to invalid
Note: See TracTickets for help on using tickets.