Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#14149 closed bug (duplicate)

REGRESSION: .data() on text nodes removed

Reported by: rok.kralj@… 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/

Change History (3)

comment:1 Changed 7 years ago by dmethvin

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.

comment:2 Changed 7 years ago by rok.kralj@…

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?

comment:3 Changed 7 years ago by dmethvin

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.

Note: See TracTickets for help on using tickets.