I want to change specific row in my table, but such has some another <span>. I want to change the value in the first span.
My code is like below:
<table id="mytable">
<tr>
<th>Book_ID</th>
<th>Title</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>
<tr>
<td>A001</td>
<td>my book</td>
<td>10000</th>
<td>
<span>3</span>
<span><a>delete</a></span>
<span>
<a href=# title="plus_qty"><img src="quantity_up.gif"></a>
</span>
<span>
<a href=# title="minus_qty"><img src="quantity_down.gif"></a>
</span>
</td>
<td>30000</td>
</tr>
</table>
Without deleting <span title="plus_qty">, and <span title="minus_qty"> or without <span> in <td> I can get and update a qty value. This my code without deleting the elements:
<table id="mytable">
<tr>
<th>Book_ID</th>
<th>Title</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>
<tr>
<td>A001</td>
<td>my book</td>
<td>10000</th>
<td>3</td>
<td>30000</td>
</tr>
</table>
jQuery code:
var row = $('#mytable').find('td');
for(i=0;i<row.length;i++){
if(row.eq(i).text() == 'A0001'){
row.eq(i+3).text(parseInt(row.eq(i+3).text())+1);
}
}
Try this:
Take care with a possible typo, in your html code you have
<td>A001</td>but in your javascript you search forA0001which is a different value, after fixing that myself my above code works.