title: How to refresh table cell with javascript
body: <p>I have a table that shows stock prices but I would like to update the stock price automatically on the page without having the user refresh the page. I have tried this </p>
  
  <pre><code>$(document).ready(function(){
      var updater = setTimeout(function(){
          $('.table #price').load('index.php', 'update=true');
      },6);
  });
  </code></pre>
  
  <p>this seems to work but it puts the whole table in the cell. I just want to refresh the price cell. Any help would be appreciated as I am new to JavaScript. I am posting the other files here also.</p>
  
  <p>This is portfolio.php</p>
  
  <pre><code>&lt;table class="table table-hover center-table table-bordered"&gt;
          &lt;tr&gt;
          &lt;th&gt;Symbol&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Shares&lt;/th&gt;
          &lt;th&gt;Price&lt;/th&gt;
          &lt;th&gt;Total&lt;/th&gt;
          &lt;/tr&gt;
  &lt;?php foreach ($shares as $row): ?&gt;
  
          &lt;tr&gt;
          &lt;td&gt;&lt;?= $row["symbol"]?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?= $row["name"]?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?= $row["shares"]?&gt;&lt;/td&gt;
          &lt;td id="price"&gt;$&lt;?= number_format($row["price"],2)?&gt;&lt;/td&gt;
          &lt;td&gt;$&lt;?= number_format($row["total"],2)?&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
  &lt;? endforeach ?&gt;
  
  &lt;tr&gt;
      &lt;td&gt;CASH&lt;/td&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;$&lt;?= number_format($cash[0]["cash"], 2)?&gt;&lt;/td&gt;
  
  &lt;/tr&gt;
  
  &lt;/table&gt;
  
  &lt;script type="text/javascript" src="js/update.js" &gt;&lt;/script&gt;
  </code></pre>
  
  <p>this is index.php</p>
  
  <pre><code>&lt;?php
  
  // configuration
  require("../includes/config.php"); 
  
  //query user's portfolio
  
  $rows = query("SELECT * FROM shares WHERE id = ?", $_SESSION["id"]);
  $cash = query("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]);
  
      //create array to store the shares
      $shares = [];
  
      //for each of the user info
  
      foreach($rows as $row){
  
          //lookup stock info
          $stock = lookup($row["symbol"]);
          if($stock !== false){
  
              $shares[] = [
                  "name" =&gt; $stock["name"],
                  "price" =&gt; $stock["price"],
                  "shares" =&gt; $row["shares"],
                  "symbol" =&gt; $row["symbol"],
                  "total" =&gt; $row["shares"]*$stock["price"]
  
              ];
  
          }
      }
  
  // render portfolio
  render("portfolio.php", ["shares" =&gt; $shares,"cash" =&gt; $cash, "title" =&gt; "Portfolio"] );   
  ?&gt;
  </code></pre>