Binding event to element dynamically

Binding event to element dynamically

  1. for (x=0;x<=10;x++) {
  2.     var tempID = 'elementName' + x;

  3.     $(jq_escape(tempID)).bind('dblclick',function(event) {
  4.         alert(tempID);
  5.     });

  6.   }
Double-clicking on any of the element will give me an alert message " elementName10" instead of elementName0 through elementName10.

Does the same thing if I tried $(.selector).dblclick(...).

Any idea why?

Thanks,
Harison