-2

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");
1
  • What do you mean by 'Fire'? Do you want jQuery to trigger the event, i.e. make an event, where there is no user event; or do you want to react on a user event? Commented Mar 14, 2019 at 13:24

2 Answers 2

-1

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"/>

Sign up to request clarification or add additional context in comments.

1 Comment

OP is asking how to fire a change event, not listen for a change event
-1

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);"/>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.