Link to home
Start Free TrialLog in
Avatar of DJ_AM_Juicebox
DJ_AM_Juicebox

asked on

Simulate mouse click?

Hi,

Is it possible to fire a mousedown event via javascript? For example, I made an element which has a mousedown handler. When clicked, it just pops up an alert:

   element.mousedown = function(evt) {
       alert("you clicked me!");
   }

I've positioned this div absolutely at 20, 20, and it is 100 pixels wide/high.

I'd like to now programatically call "mousedown" at a position of 40,40, so that should intersect my element, and its handler should be called:

   magic.simulateMouseDown(40, 40);

is that possible to do in javascript?

Thanks
SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
same thing for button, just replace the link id by button id
Avatar of SleepinDevil
SleepinDevil

But the author needs to trigger a mouse click event on X and Y coordinates, instead of just triggering a click() on an html element with Javascript....

DJ AM Juicebox I dont think this is possible with Javascript
why not at mousemove event, you can get the mouse coordinates and then you can check for specific coordinates so that you can invoke click handler.
http://www.codelifter.com/main/javascript/capturemouseposition1.html

Avatar of DJ_AM_Juicebox

ASKER

Wait is this method not correct for me?:

  https://developer.mozilla.org/En/DOM/Event.initMouseEvent

Yes, I need to trigger the mouse event at a particular coordinate (it's going to be within an SVG element, so I can borrow its native hit-testing abilities).

Thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
which all browsers you want your application to support?

Please check if the same thing works on other browsers like IE etc.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial