I create dynamically a list content:
for (var i = 0; i<length; i++) {
var $li = $('<li />', {
text: ....
}).appendTo($list);
myArray.push($li);
// This doesn't work
$(myArray).click(function (e) { alert('cc'); });
But when I get the parent of the created elements it works
// This works
$('ul.liste').first().find('li').click(function (e) {alert('cc'); });
- What's the difference between between
$(myArray)and$('ul.liste').first().find('li')? - How to correctly convert a js array to a jquery collection? I thought wrapping the array with
$()would work but obviously not.