Capture first text on first iteration

Capture first text on first iteration

Hi Everyone;

I'm using jquerymobile for a project on phonegap.

I have a dinamic listview

  1. for(i = 0; i < qtty; i++){
  2. html += "<li><a href='#listingresults' class='byCounties'>"+Counties[i].Name+", "+Counties[i].CityName+", "+Counties[i].Abbrevation+"</a></li>";
  3. }
  4. $('#counties_ li').remove();
  5. $('#counties_').append(html);
  6. $('#counties_').listview('refresh');

When I try to get the content of the link in the li using $(this).text();  the first time it always returns an empty string, but the next time I do it, I get the right text


  1. $("#counties_ li a.byCounties").live("tap", function(){
  2. $('#listViewResults a').remove();
  3. $('#listViewResults li').remove();
  4. var countyCity = $(this).text();
  5. alert(countyCity);
  6. });
When I clicked the first time the alert is empty or isn't show up. But in the second time the alert works fine.