I was trying add a check value function for further work, currently using jquery event delegation,
and the function would be according the value of #input-sample
such as if ($('#input-sample').val() <= 0)
But I don't know how to set the function work as expect.
lets say we had some input value, and some button like below:
<input id="input-sample" value="3"/>
<button class="btn btn-select">SELECT</button>
<button class="btn btn-select">SELECT</button>
<button class="btn btn-select">SELECT</button>
I create a function let the btn-select as able to click to do ajax request.
then let the $('#input-sample').val() updated each time.
$('.btn-select').click(function(e){
e.preventDefault(); // stop click go to next page
$.ajax({
xxx, xxx, xxx, // some ajax
success: function (response) {
// **** BUT! I just update the '#input-value'
$('#input-sample').val(
parseInt($('#input-sample').val() - 1)
);
});
});
After the $('#input-sample').val() was down to 0,
I would need the event delegation check it for other function.
But somehow the event delegation cannot trigger it.
I tried create other kinds of function like
$('#input-sample').change(function(){}); // no luck,
$('#input-sample').on('change', function(){}); // noluck,
$(document).on('change', '#input-sample', function(){}); // same no luck,
Is there any other function would work after the value of the #input-sample changed ?