What happens is: I create a bunch of inputs with jQuery, they can have different IDs. In them, I need to put an alert on a certain value when onChange()
happens, how can I do that? A shallow example of this is the code below that I'm trying.
let exemploIds = ['id1', 'id2', 'id3', 'id4', 'id5', 'id6'];
exemploIds.forEach(function(point) {
$('#inputs').append(`
<input id="${point}" type="number">
`)
});
exemploIds.forEach(function(point) {
$('#' + point).on('change', function() {
if ($(this).val() > 100) {
alert('Very high!')
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div id="inputs"></div>
HTMLElement.prototype.val
. Did you mean$(this).val()
?this.value
?#inputs
and do everything there...