I would do it like this:
<table width="301" border="0" cellspacing="5" cellpadding="0" id="selectedproducts" ==""> <tbody> <tr> <th width="56" scope="col">Product:</th> <th width="48" scope="col">Size:</th> <th width="71" scope="col">Colour:</th> <th width="41" scope="col">Qty</th> <th width="55" scope="col">Price</th> <th width="55" scope="col">Delete</th> </tr> <tr id="product_1"> <td>Shuttle</td> <td>54.95</td> <td>Red</td> <td>1</td> <td></td> <td><a>[X]</a></td> </tr> <tr id="product_2"> <td>Shuttle</td> <td>54.95</td> <td>Red</td> <td>1</td> <td></td> <td><a>[X]</a></td> </tr> </tbody> </table>
and jQuery:
$('tr a').live('click', function () { $(this).closest('tr').remove(); });
another alternative to this selector would be
$('tr[id^="product_"] a').live('click', function () { // you could ge the id number from the tr to do other things with var id = $(this).closest('tr').attr('id').replace("product_",""); $(this).closest('tr').remove(); });
this would limit it to only tr, whose identifier begins with "product _"
alternately you can remove the element with _id ending as follows
$('tr[id^="product_"] a').live('click', function () { // you could ge the id number from the tr var id = $(this).closest('tr').attr('id').replace("product_",""); //then you could remove anything the that ends with _id $('[id$="_'+id+'"]').remove(); });
I changed the code a bit: DEMO
source share