$.data doesn't attach the data to the actual element. jQuery attaches
a single expando containing a number to the element which refers to an
object in the $.cache object. Even events are attached this way so
don't worry about it. $.data was created for exactly the kind of thing
you are doing.

Adding stuff to a jQuery object is just going to give you a heap of
problems - none of the jQuery methods guarantee you will get the exact
same jQuery object back.

If this is no good maybe you should take a look at the jQuery-UI
framework and build upon that using it's $.widget() function.

Regards
- Mark Gibson

2009/3/9 Jeremy <[email protected]>:
>
> It is true we are attaching functions (and state) directly to the
> jQuery object which also means we have to keep a reference to that
> object. Although this isn't the official way of doing things, it
> allows us to quickly make simple, encapsulated controls.  I do see how
> we could use $.data to solve our problem but attaching everything to
> the actual DOM element is not something we really need (or want) to
> do.
>
> On Mar 7, 5:16 pm, ajpiano <[email protected]> wrote:
>> It seems like you are attaching information directly to arbitrary
>> jQuery objects, rather than using the .data() method, which from a
>> cursory read seems like it would be appropriate.
>>
>> --adam
>>
>> On Mar 7, 10:02 am, Dave Methvin <[email protected]> wrote:
>>
>> > > var button = makeNewButton().addClass('TestButton').appendTo(parent);
>>
>> > > Later we might want to disable the button with button.disable().  As
>> > > of 1.3.2, this is no longer possible as appendTo does not return the
>> > > original object.
>>
>> > But it in that case, the button variable has the element(s) that were
>> > appended to parent. Isn't that what you want? It's true that they're
>> > clones, but does that hurt anything? If you've added a .disable()
>> > plugin to jQuery it should still work on the button object.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to