Bug Tracker

Modify

Ticket #10784 (closed bug: invalid)

Opened 18 months ago

Last modified 18 months ago

$.removeData is not working in 1.7

Reported by: istvan.m.antal Owned by: istvan.m.antal
Priority: undecided Milestone: None
Component: unfiled Version: 1.7
Keywords: Cc:
Blocking: Blocked by:

Description

As of 1.7, removeData is not working, here is a simple test case:  http://jsfiddle.net/gGvHT/

After the second click, the alert should not show "test", but it still does, in other words, the data is not getting removed.

Change History

comment:1 Changed 18 months ago by dmethvin

  • Owner set to istvan.m.antal
  • Status changed from new to pending

Did you expect .removeData to remove the data attribute from the HTML? That's not how it works. The data APIs only remove the data from the internal object. When you ask for the data the next time, it finds a match in the data- attribute on the element.

The docs clearly mention this:

Removing data from jQuery's internal .data() cache does not effect any HTML5 data- attributes in a document; use .removeAttr() to remove those. --  http://api.jquery.com/removeData/

More information is here:

 http://www.learningjquery.com/2011/09/using-jquerys-data-apis

In general, if you are not interested in the performance benefit of having the data cached by jQuery, skip the .data() API altogether and work directly with .attr() on the attribute.

comment:2 Changed 18 months ago by trac-o-bot

  • Status changed from pending to closed
  • Resolution set to invalid

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

comment:3 Changed 18 months ago by istvan.m.antal

.removeData could simply set the cache to null like it probably does in earlier versions, that way I would not get back the data that is supposed to be removed.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.