tags:

views:

88

answers:

1

I used this jquery each function and iterated my json data with it....

$.each(data.Results, function() {
   divs += '<div class="resultsdiv"><br />
  <span style="display: inline-block;width:150px;" class="resultName">'
 + this.Mat_Name + '</span><span class="resultfields" style="padding-left:10px;">
 Measurement&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' 
 + this.Mes_Name + '</span>&nbsp;<a href="/Materials/Delete/' + this.Id + '">
Delete</a>&nbsp;<a href="/Materials/Details/' + this.Id + '">Details</a>&nbsp;
<a href="/Materials/Edit/' + this.Id + '">Edit</a></div>';
   });

alert(divs.length); doesnt seem to get the count.... Any suggestion...

+3  A: 

divs is a string, so divs.length would return the length of that string. You need to convert it into a DOM node, select the divs, and get the count:

$('div', '<wrapper>' + divs + '</wrapper>').length;

Alternatively, in the code you provided you could just get the length of the data.Results array:

data.Results.length;
David Fullerton