My html code is as follows:
<div id="cart-list">
<div class="col-xs-12 product-grid-item">
<span class="product-grid-id" style="display: none;">3</span>
<div class="product-info col-xs-12">
<div class="col-xs-8 product-metadata">
<div class="name">Name</div>
<div class="price">Price</div>
<div class="col-xs-6" id="delete">
<button type="submit" name="delete-btn" id="delete-btn">Delete</button>
</div>
</div>
</div>
</div>
<div class="col-xs-12 product-grid-item">
...
</div>
<div class="col-xs-12 product-grid-item">
...
</div>
<div class="col-xs-12 product-grid-item">
...
</div>
</div>
JQuery is :
$(".product-grid-item").on('click','#delete-btn',function(e) {
e.preventDefault();
var id = $(this).find(".product-grid-id").text();
deleteFromCart(id);
return false;
});
I want on delete button click, it should select the span element with class name product-grid-id and get the text in there, which is 3, in this case and pass it forward..
NOTE : There will be many product-grid-item div's in cart-list div. I need to get the id of the div on which the delete button is clicked. this delete button will be in every product-grid-item