title: jQuery returning two elements for each one it finds?
body: <p>I'll start by saying I'm fairly new to jQuery. For the most part, I've found it intuitive and powerful, but this one circumstance has me thoroughly stumped.</p>
  
  <p>In the following method, the call to <code>.each()</code> returns two elements for every one found. It iterates over a set of table rows given IDs starting with the word, "communication," and followed by an ID number. For each row it returns, it processes twice. </p>
  
  <p>Using Firebug, I've validated that the DOM only has a single instance of each table row in question. Also using Firebug, I've validated that the method is not being called twice; the iteration in <code>.each()</code> is truly going over each returned table row twice. By the time all the AJAX call goodness is done, I'll have two entries in the database for each row created in the table.</p>
  
  <p>This is the code that's causing the issues:</p>
  
  <pre><code>function getCommunications() {
      var list = $('[id^=communication]');
      var communications = new Array();
      list.each(function () {
          var communication = {
              ID: $(this).find('.commCompanyID').val(),
              /*
               * SNIP: more object properties here that are 
               * unnecessary to this discussion
               */
          };
          communications.push(communication);
      });
      return communications;
  }
  </code></pre>
  
  <p>At the point of <code>return communications</code>, the Array returned will contain twice as many elements as there are table rows. </p>
  
  <p>I should note that nearly identical code (but going against specific lists of divs) is working on the same page. It's just the table that's suffering the issues.</p>
  
  <p>I'm using jQuery 1.4.1, the version which shipped with Visual Studio .NET 2010. </p>
  
  <p>The table markup is fully dynamic -- that is, aside from the header row, it's dependent on data either returned at page load or created by the user via a dialog box. I'll drop in just the code for what's created at page load; again using Firebug I've validated that what I create dynamically when an end user creates a row with the dialog box matches. (This should be readable by anyone, but for the record this is an ASP.NET MVC 2.0 project.)</p>
  
  <pre><code>&lt;table id="commTable"&gt;
      &lt;tr&gt;
          &lt;th&gt;&lt;/th&gt;
          &lt;th&gt;
              Date / Time
          &lt;/th&gt;
          &lt;th&gt;
              Contact
          &lt;/th&gt;
          &lt;th&gt;
              Type
          &lt;/th&gt;
          &lt;th&gt;
              Duration
          &lt;/th&gt;
          &lt;th&gt;
              Notes
          &lt;/th&gt;
      &lt;/tr&gt;
  &lt;% foreach (var item in Model) { %&gt;
      &lt;tr id="communication&lt;%: item.ID %&gt;"&gt;
          &lt;td&gt;
              &lt;a href="#" onclick="showEditCommunicationForm(&lt;%: item.ID %&gt;"&gt;
                  Edit&lt;/a&gt; 
              &lt;span class="commDeleteButton"&gt;
                  &lt;a href="#" onclick="deleteCommunication(&lt;%: item.ID %&gt;)"&gt;
                      Delete&lt;/a&gt;
              &lt;/span&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;span class="commDateTime"&gt;&lt;%: item.DateTime %&gt;&lt;/span&gt;
              &lt;input type="hidden" class="commID" value="&lt;%: item.ID %&gt;" /&gt;
              &lt;input type="hidden" class="commIsDeleted" 
                  value="&lt;%: item.IsDeleted %&gt;" /&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;span class="commSourceText"&gt;&lt;%: item.Company.CompanyName %&gt;&lt;/span&gt;
              &lt;input type="hidden" class="commCompanyID" 
                  value="&lt;%: item.CompanyID %&gt;" /&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;%: item.CommunicationType.CommunicationTypeText %&gt;
              &lt;input type="hidden" class="commTypeID" 
                  value="&lt;%: item.CommunicationTypeID %&gt;" /&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;span class="commDuration"&gt;&lt;%: item.DurationMinutes %&gt;&lt;/span&gt; 
              Minutes
          &lt;/td&gt;
          &lt;td&gt;
              &lt;span class="commNotes"&gt;&lt;%: item.Notes %&gt;&lt;/span&gt;
          &lt;/td&gt;
      &lt;/tr&gt;    
  &lt;% } %&gt;
  &lt;/table&gt;
  </code></pre>