3

How can I trigger Vue event from jquery? I have

<input type='text' v-on='keypress: doSomthing()' id='demo'> .

How can I trigger this event outside of vue .. using jquery? I thought I can do

$('#demo').trigger('keypress')` 

... but it doesnt trigger the event. It does nothing. Any idea how to do it?

David Marko
  • 2,477
  • 3
  • 27
  • 58

1 Answers1

3

Vue is hooking native events. jQuery is generating events in a layer above native events. See this for more information on how to use document.createEvent to create and dispatch native events:

https://learn.jquery.com/events/triggering-event-handlers/

There's a good example here: Is it possible to simulate key press events programmatically?

Community
  • 1
  • 1
David K. Hess
  • 16,632
  • 2
  • 49
  • 73
  • 1
    Thanks a lot. jquery.simulate.js really did the trick. I can have and call it using $('#x').simulate('keypress') – David Marko Aug 25 '15 at 05:52