Šime Vidas wrote: >> In my opinion discard the data, saving the cost of a DOM access. > > Afaik, setting/getting .data() does not include an additional > performance penalty (as in page reflow), since jQuery's global cache > object is used to store the data.
Correct, there is no reflow, and nothing else extremely expensive. > If a reference to the DOM element exists beforehand, ergo, no selector > query is performed, then: > > $( elem ).data( 'arr', arr ); > > and > > $( elem ).data( 'arr' ); > > perform well. Two things, though. First, this will definitely (there I go making claims without empirical evidence again, but I'm quite certain!) be slower than direct access to a global object. Second, if you have a reference to a DOM element laying around, why not have a reference directly to the array laying around? What would it gain? -- Scott -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com