Jump to content

dispatchEvent


Matej

Recommended Posts

Events in general are pretty central to how Javascript works. Events are things like a user clicking somewhere, or just moving the mouse, or a page loading, or basically anything that happens that can be captured. DispatchEvent is a way for you to fire an event yourself without waiting for the event to actually happen. You might put a handler for a click event on a button, and when something else happens you want to fire that event as if they clicked on the button. You would use dispatchEvent to fire that event and have Javascript handle it the same way that it would any other click event.

Link to comment
Share on other sites

look at the documentation. you need to pass it an event, not a string of the event name.

https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events

Link to comment
Share on other sites

ah , so basicly i DIDNT create that simulated event , i had to create it first

 

var event = document.createEvent("Mouseevents");    event.initEvent("click",true,true);

or

 

var event = new MouseEvent('click', {'view': window,'bubbles': true,'cancelable': true})

 

Which one is better? or it just depends on me

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...