Why doesn't this work in jQuery 1.4.2?
var $list = $([]);
for(var i=0; i<50; i++) {
$list.add( $('<div/>', { id: 'jake', class: 'test' }).data('test', { hi: 'hello' }) );
}
alert($list.size()); // 0
Thanks!
Pointing back the reference list again works for me; e.g. $list = $list.add( $('<div/>') );
var $list = $([]);
for(var i=0; i<50; i++) {
$list=$list.add( $('<div/>', { 'id': 'jake'+i, 'class': 'test' }).data('test', { hi: 'hello' }) );
}
alert($list.size()); // 50
Why add
doesn't work I don't know, but you can replace it with push
due to jQuery being an Array-like object, which should do what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With