I know if you move mouse, that event will invoke however how can I invoke that event just with help of the code?
Asked
Active
Viewed 253 times
2
-
1JavaScript's [`document.createEvent`](https://developer.mozilla.org/en-US/docs/DOM/document.createEvent) (example with mouse event included) and jQuery's [`trigger`](http://api.jquery.com/trigger/) – Rob W Sep 05 '12 at 19:34
-
As Rob says to fake the event, but as Roko says - it will not actually move the cursor, that is not available in browsers. – Orbling Sep 05 '12 at 19:37
-
http://stackoverflow.com/questions/906486/how-can-i-programmatically-invoke-an-onclick-event-from-a-anchor-tag-while-kee This should probably help you, it has been asked before. – fonZ Sep 05 '12 at 19:41
3 Answers
1
AFAIK you cannot move the user's mouse pointer if that was the question.
It would be called "mousejacking" ;)
Not sure why you ask, but,
if your goal is to simulate a click on another element you could do:
$('#element_1').click(function(){
$('#element_2').click();
});

Roko C. Buljan
- 196,159
- 39
- 305
- 313
1
If you have a jQuery element from which you want to fire an event you need the trigger method
var $t = jQuery('#idToElement');
$t.trigger('mousemove',['parameter1','parameter2']);
If you want to do this with pure javascript you need the createEvent function of the document object. You can find more about that here

norbitheeviljester
- 952
- 1
- 6
- 17