I have input with type number:
<input type="number" id="input-number" onChange="DoSomething();"/>
How to fire onChange event with jQuery?
[EDIT]
Did it with following code:
$("#input_0").trigger("change");
I have input with type number:
<input type="number" id="input-number" onChange="DoSomething();"/>
How to fire onChange event with jQuery?
[EDIT]
Did it with following code:
$("#input_0").trigger("change");
With trigger
Any event handlers attached with
.on()
or one of its shortcut methods are triggered when the corresponding event occurs. They can be fired manually, however, with the.trigger()
method. A call to.trigger()
executes the handlers in the same order they would be if the event were triggered naturally by the user:
console.clear()
DoSomething = (e) => {
console.log(e.target)
}
$('#input-number').trigger('change')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="number" id="input-number" onChange="DoSomething(event);"/>
Please have a look attached example.
You need to setup the jquery function ($(selector).change())
which is fired when lost the focus from textbox.
$("#input-number").on('change',function(){
alert($(this).val());
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="number" id="input-number"/>