Jquery: finding text from sibling elements
I have dynamically generated HTML table that I want to use with JQuery. It
looks kind of like this, only with more <tr> elements.
<table>
<tr>
<td class="name"> Apples </td>
<td class="value"> 2.33 </td>
<td class="amount"> <input type="text"></td>
</tr>
</table>
The script I'm writing would take whatever's in the text input field,
multiply it by the float specified in the value td and output it. However,
I have problems getting to that <td> using JQuery.
I tried something like parseFloat($(".amount
input").parent().siblings($("td.value")).text()) to get the value, but it
doesn't work - it seems to be trying to multiply it by every element
regardless of the class. I tried a <tr> where the only data was
integers...
2013-8-28 | 2.1 | 20
...and it spat out 4026. I have no idea why.
So, the question remains: how do I get the contents of the <td> with the
class value starting from the input on the same <tr>?
No comments:
Post a Comment