I have one anchor tag and a button inside the same div parent.
Clicking on an anchor need to click the button too via code.
Below is my HTML
<div class="product_list">
<a class="action tocart primary new_add_to_cart"><span>Add to cart</span></a>
<button type="submit" id="product-addtocart-button-927" title="Add to Cart" class="main-add-tocart action tocart primary">
<span>Add to cart</span>
</button>
</div>
<div class="product_list">
<a class="action tocart primary new_add_to_cart"><span>Add to cart</span></a>
<button type="submit" id="product-addtocart-button-928" title="Add to Cart" class="main-add-tocart action tocart primary">
<span>Add to cart</span>
</button>
</div>
Below is the JavaScript code I tried to use
$(document).on('click','.new_add_to_cart',function(){
var pin = $.cookie('delivery-pincode');
if(!pin){
alert("hii2");
}
else{
$(this).closest(".main-add-tocart").trigger("click");
}
});
In the else condition I want the closest button (sibling) to be clicked, I have multiple product(parent divs with the same class .product_list) and I want only click only on the "current" product.