我有一個列表,其中包含兩種不同的項目,product-x和product-y。jQuery - 刪除'對應'項目
當用戶刪除產品x我需要它的等效產品y也刪除和反之亦然。
我已經嘗試了這兩種不同的方式,但似乎沒有工作。我感謝任何幫助!
JS
$(document).on('click', '.delete-item', function(e) {
$(this).parents('.product-x').delay(500).remove();
$(this).parents('.product-y').delay(500).remove();
});
CSS
.product-x, .product-y{
width:100px;
height:50px;
margin:10px;
}
.product-x{
border:red 1px solid;
}
.product-y{
border:navy 1px solid;
}
HTML
<div id="product-x-wrapper">
<div class="product-x">1
<button class="delete-item">x</button>
</div>
<div class="product-x">2
<button class="delete-item">x</button>
</div>
<div class="product-x">3
<button class="delete-item">x</button>
</div>
</div>
<div id="product-y-wrapper">
<div class="product-y">1
<button class="delete-item">x</button>
</div>
<div class="product-y">2
<button class="delete-item">x</button>
</div>
<div class="product-y">3
<button class="delete-item">x</button>
</div>
</div>
當你說「兄弟姐妹」時,你是指具有相同數字的人嗎? (例如1,2或3) – Pabs123
您沒有正確使用術語「兄弟」。在這種情況下,「兄弟」是與所討論的元素處於相同DOM級別/相鄰的ANY元素。你想要刪除相同的「產品y」項目,假設 - 如果它是#2,那麼刪除#2產品y? –
'兄弟'你真的相對應嗎? – j08691