title: jQuery .text() function not working
body: <p>So I am trying to have user click a button the buttons value holds a question number and a div id. I am then trying to use that question number to access text that is in a span that has the id question_no"+_text. I the line that should get the text is:</p>
  
  <pre><code>var text=$("div#"+div+" span#"+question_no+"_text").text();
  </code></pre>
  
  <p>The problem is it is working half the time. It will grab the text on some spans but not on others.</p>
  
  <p>HHere is the script I wrote:</p>
  
  <pre><code>$("button.add_answer").click(function() {
      var question_no=$(this).attr("value")
      var div=$(this).attr("data-version");
      var text=$("div#"+div+" span#"+question_no+"_text").text();
      var answer=$("div#"+div+" [name="+question_no+"]");
      var answerText;
      var answerValue;
      var checkbox=false;
  
      alert($("div#"+div+" span#"+question_no+"_text").length);
  
      if (answer[0].tagName.toLowerCase() == "input") {
          if(answer.attr("type") == "text") {
               answerText=answer.val();
               answerValue=answer.val();  
          } else if (answer.attr("type") == "radio") {
               var answer=$("div#"+div+" [name="+question_no+"]:checked");
               answerValue=answer.val();
               answerText=answer.next().text();
          } else {
               alert("checkbox");
               checkbox=true;
               $("div#"+div+" [name="+question_no+"]:checked").each(function() {
                   answerText=$(this).next().text();
                   answerValue=$(this).val();
                   $("div#saved_answers table").append("&lt;tr id=\""+question_no+"\"&gt;&lt;td&gt;"+text+"&lt;/td&gt;&lt;td&gt;"+answerText+"&lt;/td&gt;&lt;/tr&gt;");
               });    
          }
      } else if (answer[0].tagName.toLowerCase()=="textarea") {
           answerText=answer.val();
           answerValue=anser.val();   
      } else if(answer[0].tagName.toLowerCase == "select") {
           answerText=answer.find("option:selected").text();
           answerVal=answer.val();    
      }
  
      if(!checkbox) {
          $("div#saved_answers table").append("&lt;tr id=\""+question_no+"\"&gt;&lt;td&gt;"+text+"&lt;/td&gt;&lt;td&gt;"+answerText+"&lt;/td&gt;&lt;/tr&gt;");
      }
  
  });
  </code></pre>
  
  <p>And here is the markup:</p>
  
  <pre><code>&lt;div id="1527" class="Questions"&gt;
  &lt;h1&gt;Questions&lt;/h1&gt;&lt;hr&gt;&lt;br /&gt;
  
  
      &lt;ul class="error" id="498_error"&gt;&lt;/ul&gt;
      &lt;span id="498_text"&gt;Title of Representative Completing This Section&lt;/span&gt;&lt;br /&gt;
      &lt;input type="hidden" name="498_max_length" id="498_max_length" value="25"&gt;
      &lt;input type="hidden" name="498_min_value" id="498_min_value" value=""&gt;
      &lt;input type="hidden" name="498_max_value" id="498_max_value" value=""&gt;
      &lt;input type="hidden" name="498_regex_format" id="498_regex_format" value=""&gt;
      &lt;input type="hidden" name="498_system_type" id="498_system_type" value="2"&gt;
      &lt;input type="hidden" name="498_app_type_version" id="498_app_type_version" value="1527"&gt;
  
              &lt;input class="questionChoice" type="text" name="498" /&gt;
  
      &lt;br /&gt;
      &lt;button class="add_answer" value="498" data-version="1527"&gt;Add answer&lt;/button&gt;
      &lt;br /&gt;&lt;br /&gt;
  
  
      &lt;ul class="error" id="2150_error"&gt;&lt;/ul&gt;
      &lt;span id="2150_text"&gt;Signature:&lt;/span&gt;&lt;br /&gt;
      &lt;input type="hidden" name="2150_max_length" id="2150_max_length" value=""&gt;
      &lt;input type="hidden" name="2150_min_value" id="2150_min_value" value=""&gt;
      &lt;input type="hidden" name="2150_max_value" id="2150_max_value" value=""&gt;
      &lt;input type="hidden" name="2150_regex_format" id="2150_regex_format" value=""&gt;
      &lt;input type="hidden" name="2150_system_type" id="2150_system_type" value="2"&gt;
      &lt;input type="hidden" name="2150_app_type_version" id="2150_app_type_version" value="1527"&gt;
  
              &lt;input class="questionChoice" type="text" name="2150" /&gt;
  
      &lt;br /&gt;
      &lt;button class="add_answer" value="2150" data-version="1527"&gt;Add answer&lt;/button&gt;
      &lt;br /&gt;&lt;br /&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>It is correctly grabbing the text from the second question, Signature, but not the first question, Title of Representative Completing This Section. </p>
  
  <p>After the text is grabbed along with the input I am just putting them in a table.</p>
  
  <p>Any ideas on why this would only grab the text every once in while?</p>