I'm trying to bind click event in for loop but any of the remove buttons remove only the last list item. Do you have any ideas why this happens?
for ( var key in editedPredef.predefinition) {
var listItem = $("<li></li>").addClass("ui-widget-content");
listItem.text("some text");
var removeListItem = $("<span class=\"ui-icon ui-icon-closethick\"></span>");
removeListItem.click(function() {
listItem.remove();
});
listItem.append(removeListItem);
containerElement.append(listItem);
}