I have two "li" with the same class "product cg-product-wrap" each of them contains an input "variation_id". I want when i click on< span class="link"> of the "li" change the content of their input and not all input using jQuery.
here is the HTML code
<li class="product">
<div class="cg-product-wrapper">
<a href="#"><span class="link">objet1</span></a>
<form class="cart variation_color_shop" method="post" enctype="multipart/form-data">
<input type="hidden" name="variation_id" class="variation_id" value="1">
<button type="submit" class="single_add_to_cart_button btn_acheter">
Acheter
</button>
</form>
</div>
</li>
<li class="product">
<div class="cg-product-wrapper">
<a href="#"><span class="link">objet2</span></a>
<form class="cart variation_color_shop" method="post" enctype="multipart/form-data">
<input type="hidden" name="variation_id" class="variation_id" value="2">
<button type="submit" class="single_add_to_cart_button btn_acheter">
Acheter
</button>
</form>
</div>
</li>
and here is the jQuery code
(function($) {
$(document).on('click', '.link', function(e) {
$('.variation_color_shop').find('input[name="variation_id"], input.variation_id').val('newval').change();
});
})(jQuery);
Is there any solution for that?
input[name="variation_id"], input.variation_idand not just.variation_id? And ... where are you getting'newval'from?