Reputation: 1501
In jQuery, I'm creating several div elements within a class:
function class([..])
{
this.par1 = par1
[..]
// Create div
$div = $('<div></div>')
$div.attr({
'id': 'someid' + this.par1,
[..]
})
// Assign data to $div
$div.data['par1'] = this.par1
$div.data['this'] = this
// Append to document
$('#container').append($div)
}
The problem I have is that both .data['par1']
and .data['this']
are always the same when using firebug to get $('#someid1')
e.g.
I also tried first adding it to the document, and later bind the data (after re-getting the jQuery object)
What am I doing wrong?
Upvotes: 0
Views: 261
Reputation: 33318
Try div.data('par1',this.par1);
for setting and div.data('par1');
for getting data.
Upvotes: 1