Jquery:: How can select clicked element in table without define unique id for each element

Posted by Yosef on Stack Overflow See other posts from Stack Overflow or by Yosef
Published on 2010-05-12T10:00:42Z Indexed on 2010/05/12 10:04 UTC
Read the original article Hit count: 423

Filed under:

Hello,

I have table (that generated by server) below. I want to get input element value class="itemQuantity" of clicked row. I write Jquery code but he missing "this" of clicked element.

<script type="text/javascript">
$(document).ready(function() {
$('.updateButton').click(function() {
    alert($('.itemQuantity').val());
});
});
</script>

How Can I do it with jquery(I thinking to use this and not create id for each element, but I have low knoledge in jquery).

Thanks, Yosef

<table id="items">
<tr>
<th>item id</th>
<th>item name</th>
<th>item quantity</th>
<th>item update</th>
</tr>
<tr>

<td class="itemID">
1
</td>

<td class="itemName">
Ferari
</td>
<td >
<input  class="itemQuantity"  type="text" size="4"/>
</td>
<td>
<button class="updateButton" >update item</button>
</td>
</tr>
<tr>

<td class="itemID">
2
</td>

<td class="itemName">
Fiat
</td>
<td >
<input  class="itemQuantity"  type="text" size="4"/>
</td>
<td>
<button class="updateButton" >update item</button>
</td>
</tr>

<tr>

<td class="itemID">
3
</td>

<td class="itemName">
Hundai
</td>
<td >
<input  class="itemQuantity"  type="text" size="4"/>
</td>
<td>
<button class="updateButton" >update item</button>
</td>
</tr>

</table>

© Stack Overflow or respective owner

jQuery: How can select clicked element in table without define unique id for each element

Posted by Yosef on Stack Overflow See other posts from Stack Overflow or by Yosef
Published on 2010-05-12T10:00:42Z Indexed on 2010/05/12 10:14 UTC
Read the original article Hit count: 423

Filed under:

Hello,

I have table (that generated by server) below. I want to get input element value class="itemQuantity" of clicked row. I write jQuery code but he missing "this" of clicked element.

<script type="text/javascript">
$(document).ready(function() {
    $('.updateButton').click(function() {
        alert($('.itemQuantity').val());
    });
});
</script>

How can I do it with jQuery (I thinking to use this and not create id for each element, but I have low knowledge in jQuery).

Thanks, Yosef

<table id="items">
<tr>
<th>item id</th>
<th>item name</th>
<th>item quantity</th>
<th>item update</th>
</tr>
<tr>

<td class="itemID">
1
</td>

<td class="itemName">
Ferari
</td>
<td >
<input class="itemQuantity" type="text" size="4" />
</td>
<td>
<button class="updateButton">update item</button>
</td>
</tr>
<tr>

<td class="itemID">
2
</td>

<td class="itemName">
Fiat
</td>
<td >
<input class="itemQuantity" type="text" size="4" />
</td>
<td>
<button class="updateButton">update item</button>
</td>
</tr>

<tr>

<td class="itemID">
3
</td>

<td class="itemName">
Hundai
</td>
<td >
<input class="itemQuantity" type="text" size="4" />
</td>
<td>
<button class="updateButton">update item</button>
</td>
</tr>    
</table>     

© Stack Overflow or respective owner

Related posts about jQuery