我有以下结构
<tr>
<td class="product-remove">
<div><a href="#" class="remove remove-favorite-items" title="Remove this item">×</a></div>
</td>
<td class="product-thumbnail">
<a href="http://localhost/test/product/patient-ninja/">
<img width="90" height="90" src="http://localhost/test/wp-content/uploads/2013/06/hoodie_3_front.jpg" class="attachment-shop_thumbnail wp-post-image" alt="cd_6_angle"></a>
</td>
<td class="product-name">
<input type="hidden" value="50" class="product_id_hidden"> <-- want to get this value
<a href="http://localhost/test/product/patient-ninja/">Patient Ninja</a>
</td>
<td>
<a href="javascript:void(0);" onclick="checkforstock('http://localhost/test/wp-content/plugins/dvin-wcwl/add-to-cart.php?wlist_item_id=7','In','false');">Add To Cart</a>
</td>
</tr>
当我点击<div><a href="#" class="remove remove-favorite-items" title="Remove this item">×</a>
我所做的是以下
var product_id = $(this).parent('td').find('input[type=hidden]').val(); // get the product id
怎么办?
答案 0 :(得分:2)
尝试此操作:使用.closest()
查找父tr
,然后使用.find()
获取隐藏的输入。
var product_id = $(this).closest('tr').find('input[type=hidden]').val();
答案 1 :(得分:1)
你应该试试这个:
$(function(){
$(".remove.remove-favorite-items").click(function(e){
e.preventDefault();
var product_id = $(this).parent().parent().parent().find('.product_id_hidden').val();
alert("Deteting item id: " + product_id);
});
});