title: Converting string to number in javascript/jQuery
body: <p>Been trying to convert the following to number:</p>
  
  <pre><code>&lt;button class="btn btn-large btn-info" data-votevalue="1"&gt;
      &lt;strong&gt;1&lt;/strong&gt;
  &lt;/button&gt;
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>var votevalue = parseInt($(this).data('votevalue'));
  </code></pre>
  
  <p>I've also tried <code>Number()</code> but I'm still getting <code>NaN</code> when checking the result. What am I doing wrong?</p>
  
  <p>Here is the complete code:</p>
  
  <pre><code>&lt;div class="span7" id="button-group"&gt;
      &lt;div class="btn-group"&gt;
          &lt;button class="btn btn-large btn-info" data-votevalue="1"&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/button&gt;
          &lt;button class="btn btn-large btn-info" data-votevalue="2"&gt;&lt;strong&gt;2&lt;/strong&gt;&lt;/button&gt;
          &lt;button class="btn btn-large btn-info" data-votevalue="3"&gt;&lt;strong&gt;3&lt;/strong&gt;&lt;/button&gt;
          &lt;button class="btn btn-large btn-info" data-votevalue="4"&gt;&lt;strong&gt;4&lt;/strong&gt;&lt;/button&gt;
          &lt;button class="btn btn-large btn-info" data-votevalue="5"&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;/button&gt;
          &lt;button class="btn btn-large btn-info" data-votevalue="6"&gt;&lt;strong&gt;6&lt;/strong&gt;&lt;/button&gt;
          &lt;button class="btn btn-large btn-info" data-votevalue="7"&gt;&lt;strong&gt;7&lt;/strong&gt;&lt;/button&gt;
          &lt;button class="btn btn-large btn-info" data-votevalue="8"&gt;&lt;strong&gt;8&lt;/strong&gt;&lt;/button&gt;
          &lt;button class="btn btn-large btn-info" data-votevalue="9"&gt;&lt;strong&gt;9&lt;/strong&gt;&lt;/button&gt;
          &lt;button class="btn btn-large btn-info" data-votevalue="10"&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;/button&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>$('#button-group button').each(function() {
      $(this).click(function() {
          $(this).addClass('active');
          var votevalue = parseInt($(this).data('votevalue'));
          var filename = $('.mainimage').data('filename');
          var votes = parseInt($('.mainimage').data('numvotes'));
          var totalscore = parseInt($('.mainimage').data('totalscore'));
          $.ajax({
              type: 'POST',
              url: 'index.php/?category=vote',
              data: {
                  "votevalue": votevalue,
                  "filename": filename
              },
              success: function() {
                  votes++;
                  alert(votes);
                  var average = ((totalscore + votevalue) / votes);
                  $('#vote-incremenet').html(votes);
                  $('#display-average').html(average);
                  $('#display-average').show();
                  $('#button-group button').each(function(){
                      $(this).unbind('click');
                  });
              }
          }); // end ajax
      }); // end click
  }); // end each
  </code></pre>