How to get the text in the previous element and do some maths
<p>I have the following structure:</p>

<pre><code>&lt;table&gt;
  &lt;tr&gt;
    &lt;td&gt;first&lt;/td&gt;
    &lt;td class="price"&gt;__&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" class="quantity"&gt;&lt;/td&gt;
    &lt;td class="amount&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
</code></pre>

<p>Inside the <code>&lt;td class="price"&gt;</code> goes a value that is retrieved through AJAX function.</p>

<p>So I have this on my javascript file:</p>

<pre><code>jQuery(function($) {
$(document).ready(function() {
    // alert('document ready');

    $("input.quantity").live("blur", function() {
        var $this = $(this);

        quantity = $this.val();
        price = $this.prev("td.price").text();
        alert(price);
        amount = quantity * price;
        $this.next("td.amount").html(amount);
    });
  });
});
</code></pre>

<p>but price returns nil (even price being loaded correctly thro my ajax function)</p>

<p>EDIT: This is the final code following all suggestions below. Thank you all!</p>

<pre><code>$("input.quantity").live("blur", function() {
        var $this = $(this);

        quantity = parseInt($this.val()); // in this case, people can't buy a 1 item and a half for example.

        price = $this.parents("tr").find("td.price").text();
        price = parseFloat(price);  // price can have "cents"

        amount = quantity * price;
        amount = Number(amount).toFixed(2); // I should be able to see at least 2 first decimal digits from the amount.

        $this.parent().next("td.amount").html(amount);
    });
</code></pre>
