object consisting of jQuery element

Posted by Adam Kiss on Stack Overflow See other posts from Stack Overflow or by Adam Kiss
Published on 2010-03-31T12:30:45Z Indexed on 2010/03/31 12:33 UTC
Read the original article Hit count: 122

Filed under:
|
|

hello,

current code

I've built function to do something over collection of jQuery elements:

var collection = $([]); //empty collection

I add them with:

collection = collection.add(e);

and remove with:

collection = collection.not(e);

It's pretty straightforward solution, works nicely.

problem

Now, I would like to have an object consisting of various settings set to any jQuery element, i.e.:

function addObject(e){
  var o = {
    alpha: .6 //float
    base: {r: 255, g: 255, b: 255} //color object
  }

  e.data('settings', o);
}

But when I pass jQuery object/element to function (i.e. as e), calling e.data doesn't work, although it would be simplest and really nice solution.

question

If I have an "collection" of jQuery elements, what is the simplest way of storing some data for each element of set?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about storing-data