var sum = 0;
$(document).on("input", ".payments", function() {
var amount = 100;
var values = [];
$('input').each(function(index, element) {
values.push(parseInt($(element).val(), 10) || 0);
});
var total = values.reduce(function(sum, val) {
return sum + val;
}, 0);
var diff = amount - total;
if ($(this).is(':last-child')) {
if (diff > 0) {
console.log("last not ok")
} else {
console.log("last ok")
}
} else {
if (diff >= 0) {
console.log("ok")
} else {
console.log("not ok")
}
}
})
input{display:block}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="payments" />
<input type="text" class="payments" />
<input type="text" class="payments" />
<input type="text" class="payments" />
<input type="text" class="payments" />
<input type="text" class="payments" />
<input type="text" class="payments" />
In the demo when I input in the box and reached the last box it does not go in the condition of last box.
I want to be able to tell if the one i'm inputting on(typing on) is the last box of the class payment.
$( ".payments:last-child" )or for css.payments:last-child{}$( ".payments:last-child" )but it didnt work. i want to know if the one I am inputing on is the last child of class payment