title: jQuery cant get parent element using .parent()
body: <p>I am a quite new to JavaScript and jQuery.</p>
  
  <p>I am writing a website that used AJAX to update the rating of a file to the server. The idea is that when I get the response (i.e. success or failure) I should update some values of a table. However, I am having a lot of trouble because I cannot seem to be able to correctly navigate through the DOM.</p>
  
  <p>The fragment of interest of my HTML is something like this:</p>
  
  <pre><code>&lt;tr&gt;
      &lt;td&gt;&lt;a href="some_url"&gt;some_name&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;Yes&lt;/td&gt;
      &lt;td&gt;Tag&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
  
      &lt;td&gt;&lt;button value="UP" onClick="rate(this, 'some_key', 'upvote', 'some_url' );"&gt;
              &lt;span class="glyphicon glyphicon-thumbs-up" style="font-size: 1.2em"&gt;&lt;/span&gt;
          &lt;/button&gt;
        &lt;button value="DOWN" class="btn btn-default down_vote_button table-buttons" onClick="rate(this, 'some_key', 'downvote', 'some_url' );"&gt;
              &lt;span class="glyphicon glyphicon-thumbs-down" style="font-size: 1.2em"&gt;&lt;/span&gt;
          &lt;/button&gt;
        &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>My jQuery is as follows:</p>
  
  <pre><code>function rate(caller, key, action, action_url){
      $.ajax({
          type: "POST",
          url: action_url,
          dataType: 'json',
          data: JSON.stringify({"key": key, "action": action })
      })  
      .done(function( data ) { 
          if(action == 'upvote') {
              var upvotes = $(caller).parent("tr").eq(3).text();
              alert("upvoted: " + upvotes);
          } else if(action == 'downvote') {
              var downvotes = $(caller).parent("tr").eq(4).text();
              alert("downvoted: " + downvotes);
          }
      })  
      .fail(function( data ) { 
          alert( "File action '" + action + "' failed. Please try again later." );
      }); 
  };  
  </code></pre>
  
  <p>What I thought is that if there is a successful return code from the server then I pass a reference to the button that triggered the action (hence the rate(this,....) call) and then I should get the parent  of that button and finally the correct  index so that I can get the text inside. However, for some reason I never actually get the text. I tried getting just the parent of the button and I cant get it either.</p>
  
  <p>Note that the table is supposed to have many entries and can vary depending on whats stored in a database.</p>
  
  <p>Help would be greatly appreciated.</p>
  
  <p>Thanks!</p>