I do have a button to clone a input field. This input field should trigger a value in a second field after the own value was changed.
But the problem is it does only work on the first one and not on the cloned one.
$(".products:last #automenge").on("change", function() {});
It does work to change the value of the last like:
$(".products:last #autopreisges").val(gesamptpreis);
But the change function seem to not work like that.
Now working snippet !
var products = $(".products").clone();
$('#clone-search').click(function() {
var clonedRow = products.clone().insertAfter(".products:last").find(":input").val(this.value).end();
});
$(".products:last .clautomenge").on("change", function() {
alert("wow");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="products">
<input class="clautomenge" type="text" value="1" name="Menge[]" placeholder="Menge" required />
</div>
<button id="clone-search" class="formstylebutton" type="button">
add one
</button>
A fiddle: https://jsfiddle.net/awq7sy69/