Create events dynamically for listview

Create events dynamically for listview

Hi All,

Dynamically created the listview elements. I have to create event for those list items.
I tried like this :
  1.  $.each(singles, function (key, value) {                     
  2.                         $("#Div1").append('<h4></h4><ul data-role="listview"><li><a href="#ShipsRef" onclick="fnTest(' + value.SHIP_CODE + ');">' + value.SHIP_CODE + '</a></li></ul>');
  3.                         $("#Div1").trigger("create");
  4.                     });

  5.  function fnTest(obj) {
  6.             alert(obj);
  7.         }

  8. If i select the first list item, am able to get the value of the list item. If i click second item its throwing error as Undefined.

  9. Can you please advice/suggest how to avoid it?

Thanks
Divakar