1

Is there a way to create a click event(or effect) that repeat the last click.

I need no jQuery nor Mootools nor any other javascript lib, just in pure JavaScipt.

1

2 Answers 2

2

See createEvent and dispatchEvent and an example usage shown here: Is it possible to trigger a link's (or any element's) click event through JavaScript?

Sign up to request clarification or add additional context in comments.

Comments

1

You want to Google for 'firing events manually in JavaScript' or 'simulate events in JavaScript'.

Since you captured the last event, you know what it is and can feed it into a function. Put a timer or counter on it to stop after a specified period of time or repeats.

Here is some sample code:

function fireEvent (element, event) {
   if (document.createEventObject) {
   // dispatch for IE
   var evt = document.createEventObject ();
   return element.fireEvent ('on' + event, evt)
} else{
   // dispatch for firefox + others
   var evt = document.createEvent ("HTMLEvents");
   evt.initEvent (event, true, true ); // event type, bubbling, cancellable
   return !element.dispatchEvent (evt);
}

Check this site:

http://lifescaler.com/2008/04/simulating-mouse-clicks-in-javascript/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.