Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

record jQUery element inside a array

Tags:

html

jquery

I declared a array variable els = []; in which I want to store jquery elments which are created at some point within certain events:

els[file.id] = $('<li></li>');
$('body').append(els[file.id]);

file.id is a unique id generated by the plupload script which I'm using (the event is from it)

But it doesnt work, the array is always empty...

like image 803
Alex Avatar asked Nov 28 '11 17:11

Alex


1 Answers

Arrays can only have sequential, numeric keys. You can't choose arbitrary keys. To use arbitrary key-value pairs, use an object:

var els = {};

With that said, the code you've written should still work (even though els.length would be 0) – perhaps this isn't a complete code sample?

like image 72
lonesomeday Avatar answered Nov 15 '22 05:11

lonesomeday