0
$('#btn').on('click', function(){
    console.log('323');
});

$('#btn').click();
console is written `323`

I want the same with input event, like this:

$('#inp').on('input', function(){
    console.log('323');
});

$('#inp').input();

error - input is not a function

So how to simulate input event?

0

1 Answer 1

1

Call trigger on the element, passing the name of the event whose jQuery handler you want to invoke:

$('#inp').on('input', function(){
    console.log('323');
});

$('#inp').trigger('input');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="inp">

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

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.