1

I'm using the code below within a loop. It works so long as I'm not using IE.

var remove = document.createElement("input");
remove.type = "button";
remove.value = "x";
if (remove.addEventListener) { 
remove.addEventListener("click", (function(item_id) { return function() { remove_from_cart(item_id); } })(item_id), false);
} else {
remove.attachEvent("click", (function(item_id) { return function() { remove_from_cart(item_id); } })(item_id));
}
rollsRLS8822
  • 47
  • 2
  • 7

1 Answers1

0

IE needs to have the on when describing the event so this is what you need.

remove.attachEvent("onclick", (function(item_id) { return function() { remove_from_cart(item_id); } })(item_id));
}
qw3n
  • 6,236
  • 6
  • 33
  • 62