Matej Posted September 3, 2014 Share Posted September 3, 2014 Hi , would anyone be so kind and explained the dispatchEvent() to me? i've been looking after it but i did not understand it from mozilla , IE developers and so on Thanks for asnwers Link to comment Share on other sites More sharing options...
justsomeguy Posted September 3, 2014 Share Posted September 3, 2014 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 More sharing options...
Matej Posted September 3, 2014 Author Share Posted September 3, 2014 (edited) THanks for answer so basicly it simulates the event? so why this thing does not work ? http://jsfiddle.net/19cbevvn/ Edited September 3, 2014 by Matej Link to comment Share on other sites More sharing options...
thescientist Posted September 3, 2014 Share Posted September 3, 2014 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 More sharing options...
Matej Posted September 3, 2014 Author Share Posted September 3, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now