Simulate mouse click?

DJ_AM_Juicebox
DJ_AM_Juicebox used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
yes
var link = document.getElementById['yourLinksIdAttrbuteValue'];
link.click();
same thing for button, just replace the link id by button id
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
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

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

Author

Commented:
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
which all browsers you want your application to support?

Please check if the same thing works on other browsers like IE etc.
From memory I think hes trying to make it work on FireFox and Opera?

Anyway I like the links trungk43 showed. Maybe you could trigger a x,y coordinate mouseclick event with

long screenXArg  -  Specifies the Event's screen x coordinate.  
long screenYArg  -  Specifies the Event's screen y coordinate.  
long clientXArg  -  Specifies the Event's client x coordinate.  
long clientYArg  -  Specifies the Event's client y coordinate.  

those things set like trungk43's link to "http://www.zvon.org/xxl/DOM2reference/Output/Events/method_initMouseEvent_MouseEvent.html" shows.

And using initMouseEvent (method )  in the way that other link trungk43 showed.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial