Thanks John, that makes complete sense, I too am not sure why jQuery UI doesn't use a counter either.
In my own code I have a plugin that generates an id if one is not already present on an element: (function($) { var prefix = 'id' + (+new Date()) + '-', count = 0; // Get the id of an element, or generate a unique id if it lacks one $.id = function( elem ) { if ( !elem.id ) { elem.id = prefix+(++count); } return elem.id; }; // Returns a space separated list of the id's of the elements $.fn.idrefs = function() { return Array.prototype.join.call($(this).map(function() { return $.id(this); }), ' '); }; })(jQuery); Maybe something along these lines would be useful in the core as a clear and standard alternative to $.data(elem) - Mark 2009/10/14 John Resig <jere...@gmail.com>: > > Hi Mark - > > This was intentional. We could no longer guarantee that an ID would be > attached for an element at all times (which is what was done before). > Additionally calling that method would attach an expando and object to > an empty element - even if no data needed to be stored (which is bad). > Almost universally the use of $.data(elem) was used to get at the > entirety of an element's data collection - which is what is now > returned from $.data(elem) instead. > > Looking at the tabs code it looks like they're using it to generate a > unique ID (but it's not clear as to why they need $.data for this - > they could, just as easily, keep a global ID counter and assign it to > the element if it doesn't have one, already. There's no need to attach > an entire data object just to get at that information. > > As it stands the next version of jQuery UI will require jQuery 1.4 so > this is definitely one place where we could make that clean break. If > it does become problematic, though (especially for other plugins), > then we could look into ways of changing it. > > --John > > > > On Wed, Oct 14, 2009 at 10:24 AM, Mark Gibson <jollyt...@gmail.com> wrote: >> >> Hi, I've noticed that the behaviour of $.data() has changed in 1.4pre, >> >> $.data(elem) no longer returns the cache id, it returns all the data >> items or null. >> this will probably break a lot of code (already breaks jQuery UI Tabs) >> >> Is this intentional, or a bug? >> >> - Mark. >> >> > >> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---