Skip to main content

Bug Tracker

Side navigation

#14149 closed bug (duplicate)

Opened July 18, 2013 11:46AM UTC

Closed July 18, 2013 01:06PM UTC

Last modified July 18, 2013 01:31PM UTC

REGRESSION: .data() on text nodes removed

Reported by: rok.kralj@gmail.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.3
Keywords: Cc:
Blocked by: Blocking:
Description

Hello, I have spotted a regression (the cause my and a lot of other websites broke):

el = $('<p>dasdasd</p>').contents(); // create text node
$(el).data('test', 'test');
$(el).data();

This returns empty object, and this is really inconvenient.

This kind of functionality was the basis for my smart localisation plugin, which can be seen here (click the flag button on the right multiple times):

http://valat.si/

Attachments (0)
Change History (3)

Changed July 18, 2013 01:06PM UTC by dmethvin comment:1

resolution: → duplicate
status: newclosed

Duplicate of #12197.This is similar to #12197 so I'll mark it as a duplicate. The code you show here won't work on IE 6, 7, or 8 and we've never supported storing data on text nodes, although it may have worked on some browsers.

Changed July 18, 2013 01:20PM UTC by rok.kralj@gmail.com comment:2

No, this is not a duplicate. That bug was about the .clone(), .data() worked. Now even the .data() doesn't work.

>> The code you show here won't work on IE 6, 7, or 8

We are talking about the 2.x branch, which doesn't include these browsers.

>> we've never supported storing data on text nodes

I have never eaten a lobster, but I might someday. Why not support that? Does it contribute too much towards the code size? Is it possible to make it as a plugin?

Isn't the point of discarding oldIE to enable such advanced functionality?

Changed July 18, 2013 01:31PM UTC by dmethvin comment:3

The reasons are the same as given in that ticket. jQuery isn't meant to manipulate text nodes. There are only a few ways you can even get them into a collection. We have never supported using .data() with text nodes, and if we implemented it consistently across the API we'd need to do it both for your case and the one in #12197 as well as many others no doubt undiscovered.

We've pledged that we would keep the behaviors of the two branches consistent between 1.x and 2.x to prevent unpleasant surprises as people move code across.

The easiest way to attach data to text nodes on browsers that support it would be to use .prop() I'd think.

You should definitely try lobster, unless you have a shellfish allergy.