title: jQuery Code: Starting from Parent to Child; not from Child to Parent
body: <p>I have the following HTML table. In the last column of each row there are three buttons. When view button is clicked, I need to get the consumer ID of the corresponding row. I have the following jQuery code. <a href="http://jsfiddle.net/Lijo/nUbB2/" rel="nofollow">http://jsfiddle.net/Lijo/nUbB2/</a></p>
  
  <p>1)  Is there a better jQuery code?</p>
  
  <p>2)  Currently I am first finding the button – then its parent row – then the Consumer ID column. Is there a way to start from the row and then find the button and Consumer ID column respectively?</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;title&gt;
  
   &lt;/title&gt;
  
  &lt;script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
      $(document).ready(function () {
  
          $('.resultGridTable tr &gt; td &gt; .actionButtonView').click(function () {
              //TRaversing to get the parent row and then the required columns in the row
              var consumerID = $(this).parents('tr:first').find('td:first').text();
              var consumerName = $(this).parents('tr:first').find('td:nth-child(2)').text();
              var configID = $(this).parents('tr:first').find('td:nth-child(5)').text();
  
              alert(consumerID + "," + consumerName + "," + configID);
  
              //window.location.href("SubscribedAssociates.aspx?ConsumerID=" + consumerID + "&amp;consumerName=" + consumerName + "&amp;configID=" + configID);
              return false;
  
          });
  
      });
  &lt;/script&gt;
  &lt;/head&gt;
  
  
  &lt;body&gt;
  &lt;table class="resultGridTable" cellspacing="0" id="detailContentPlaceholder_grdConsumers"
      style="border-collapse: collapse;"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th scope="col"&gt;
                  &lt;a&gt;Consumer ID&lt;/a&gt;
              &lt;/th&gt;
              &lt;th scope="col"&gt;
                  &lt;a&gt;Consumer Name&lt;/a&gt;
              &lt;/th&gt;
              &lt;th scope="col"&gt;
                  &lt;a&gt;Consumer URL&lt;/a&gt;
              &lt;/th&gt;
              &lt;th scope="col"&gt;
                  &lt;a&gt;Status&lt;/a&gt;
              &lt;/th&gt;
              &lt;th scope="col"&gt;
                  &lt;a&gt;Config ID&lt;/a&gt;
              &lt;/th&gt;
              &lt;th scope="col"&gt;
                  Action
              &lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;a href="SubscribedAssociates.aspx?ConsumerID=101"&gt;101&lt;/a&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  Consumer1
              &lt;/td&gt;
              &lt;td&gt;
                  http://Consumer1.compnay.com/wps/payroll
              &lt;/td&gt;
              &lt;td&gt;
                  Active
              &lt;/td&gt;
              &lt;td&gt;
                  101
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="submit" name="ctl00$detailContentPlaceholder$grdConsumers$ctl02$btnView"
                      value="VIEW" id="detailContentPlaceholder_grdConsumers_btnView_0" class="actionButtonView"
                      style="color: White; background-color: Orange; font-weight: bold; width: 35px" /&gt;
                  &lt;input type="submit" name="ctl00$detailContentPlaceholder$grdConsumers$ctl02$btnEdit"
                      value="EDIT" id="detailContentPlaceholder_grdConsumers_btnEdit_0" class="actionButtonEdit"
                      style="color: White; background-color: Orange; font-weight: bold; width: 35px" /&gt;
                  &lt;input type="submit" name="ctl00$detailContentPlaceholder$grdConsumers$ctl02$btnDelete"
                      value="DELETE" id="detailContentPlaceholder_grdConsumers_btnDelete_0" class="actionButtonDelete"
                      style="color: White; background-color: Orange; font-weight: bold; width: 45px" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr style="background-color: #E5E5E5;"&gt;
              &lt;td&gt;
                  &lt;a href="SubscribedAssociates.aspx?ConsumerID=102"&gt;102&lt;/a&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  Consumer2
              &lt;/td&gt;
              &lt;td&gt;
                  http://Consumer2.compnay.com/prd/sap/operations
              &lt;/td&gt;
              &lt;td&gt;
                  Active
              &lt;/td&gt;
              &lt;td&gt;
                  102
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="submit" name="ctl00$detailContentPlaceholder$grdConsumers$ctl03$btnView"
                      value="VIEW" id="detailContentPlaceholder_grdConsumers_btnView_1" class="actionButtonView"
                      style="color: White; background-color: Orange; font-weight: bold; width: 35px" /&gt;
                  &lt;input type="submit" name="ctl00$detailContentPlaceholder$grdConsumers$ctl03$btnEdit"
                      value="EDIT" id="detailContentPlaceholder_grdConsumers_btnEdit_1" class="actionButtonEdit"
                      style="color: White; background-color: Orange; font-weight: bold; width: 35px" /&gt;
                  &lt;input type="submit" name="ctl00$detailContentPlaceholder$grdConsumers$ctl03$btnDelete"
                      value="DELETE" id="detailContentPlaceholder_grdConsumers_btnDelete_1" class="actionButtonDelete"
                      style="color: White; background-color: Orange; font-weight: bold; width: 45px" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>