2013-09-28 69 views
1

我有這個項目在我的HTML刪除項目:查找和數據屬性

<p class="choose-item" data-product-id = "{{ listprod.id }}"></p> 

,我需要通過使用數據屬性將其刪除。我發現不起作用:

$(".choose-item").find("[data-product-id=" + Model.get('old_prod_id') + "]").remove(); 

其中Model.get('old_prod_id')是需要的項目ID。有人可以幫我做這個嗎?

回答

2

您應該使用.filter()方法,而不是.find().find()選擇後代所選元素的元素,但在這裏你要.filter()集合(選定的元素)。

$(".choose-item").filter("[data-product-id='" + Model.get('old_prod_id') + "']") 
       .remove(); 
+0

謝謝,它的工作 – user2706783

+0

@ user2706783不客氣。 – undefined

0

什麼是.choose-items家長。使用它。

$("body").find("[data-product-id=" + Model.get('old_prod_id') + "]").remove(); 

取代body代替.choose-items父標籤的類名或ID。