title: Getting JavaScript table element from span element
body: <p>I am using the table in for format:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;table class=&quot;list&quot; id='obid'&gt;
      &lt;thead&gt;
          &lt;tr&gt;
             &lt;th&gt;Id&lt;/th&gt;
             &lt;th&gt;name&lt;/th&gt;
             &lt;th&gt;address&lt;/th&gt; 
             &lt;th&gt;city&lt;/th&gt; 
             &lt;th&gt;country&lt;/th&gt; 
             &lt;th&gt;province&lt;/th&gt; 
             &lt;th&gt;postalcode&lt;/th&gt; 
             &lt;th&gt;primaryphone&lt;/th&gt; 
             &lt;th&gt;secondaryphone&lt;/th&gt; 
             &lt;th&gt;website&lt;/th&gt; 
          &lt;/tr&gt;
      &lt;/thead&gt;
  &lt;/table&gt;
  </code></pre>
  <p>When the table is clicked I can receive the whole of the data from each row which works fine. However it pulls the span HTML text as well.</p>
  <pre class="lang-html prettyprint-override"><code>&quot;span style=&quot;cursor:pointer;&quot;&gt;2&lt;/span&quot;
  </code></pre>
  <p>How would I go about just puling the value &quot;2&quot;? Currently I have this:</p>
  <pre><code>var table = document.getElementsByTagName(&quot;table&quot;)[0];
  var tbody = table.getElementsByTagName(&quot;tbody&quot;)[0];
  tbody.onclick = function (e) {
      e = e || window.event;
      var data = [];
      var target = e.srcElement || e.target;
      while (target &amp;&amp; target.nodeName !== &quot;TR&quot;) {
          target = target.parentNode;
      }
      if (target) {
          var cells = target.getElementsByTagName(&quot;td&quot;);
          for (var i = 0; i &lt; cells.length; i++) {
              data.push(cells[i].innerHTML);
          }
      }
      console.log(data[0]);  
  };
  
  
  
  
  </code></pre>
  <p>MY html is created as so:</p>
  <pre><code>$res=array();
  if($result)
      if(mysql_num_rows($result)&gt;0)
      {
          while(($data = mysql_fetch_array($result)) !== false)
          {
          
              
              $r=array();
              
      
              
              
              
              $r[]=&quot;&lt;span style='cursor:pointer;'  &gt;&quot;.$data['id'].&quot;&lt;/span&gt;&quot;;
              $r[]=&quot;&lt;span style='cursor:pointer;'  &gt;&quot;.$data['name'].&quot;&lt;/span&gt;&quot;;
              $r[]=&quot;&lt;span style='cursor:pointer;'  &gt;&quot;.$data['address'].&quot;&lt;/span&gt;&quot;;
              $r[]=&quot;&lt;span style='cursor:pointer;'  &gt;&quot;.$data['city'].&quot;&lt;/span&gt;&quot;;
              $r[]=&quot;&lt;span style='cursor:pointer;'  &gt;&quot;.$data['country'].&quot;&lt;/span&gt;&quot;;
              $r[]=&quot;&lt;span style='cursor:pointer;'  &gt;&quot;.$data['province'].&quot;&lt;/span&gt;&quot;;
              $r[]=&quot;&lt;span style='cursor:pointer;'  &gt;&quot;.$data['postalcode'].&quot;&lt;/span&gt;&quot;;
              $r[]=&quot;&lt;span style='cursor:pointer;'  &gt;&quot;.$data['primaryphone'].&quot;&lt;/span&gt;&quot;;
              $r[]=&quot;&lt;span style='cursor:pointer;'  &gt;&quot;.$data['secondaryphone'].&quot;&lt;/span&gt;&quot;;
              $r[]=&quot;&lt;span style='cursor:pointer;'  &gt;&quot;.$data['website'].&quot;&lt;/span&gt;&quot;;
              
              $res[]=$r;
              
              
          }
          
      }
  
  
  echo json_encode($res);
  </code></pre>