1

Do you know a JS library for DOM events simulation? I know that this operation can be done but i can't find any library to do it.

UPDATE: I try to explain better my question. Javascript can simulate events like the user click, i'm looking for a library that helps me with this operation.

4
  • I mean javascript can simulate an event like the user click. I want to know if there's a library to simplify this operation. Commented Mar 26, 2010 at 16:03
  • Please clarify if simply calling handlers attached to an element is good enough "simulation" for you. Commented Mar 26, 2010 at 16:07
  • The event simulation allows you to specify some details to build the event object to pass into the hendlers, so it's a little more complex. Commented Mar 26, 2010 at 16:19
  • yep, and some libraries (jQuery) simulate events with a fake event object and simply call the handlers attached to the element (faking out event bubbling too). Other libraries (eg Prototype, YUI) route to one of dispatchEvent/fireEvent with a real event object. There are pros and cons to both approaches. Which one are you looking for? Commented Mar 26, 2010 at 16:31

4 Answers 4

5

Kangax made a very useful set of extensions for the PrototypeJS framework, the one that might interest you is Event.simulate

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

Comments

2

http://developer.yahoo.com/yui/3/event/#eventsimulation

""" Simulated events are browser-created events that, most of the time, behave exactly as user-initated events. Events bubble as they normally would and event objects are created with properties containing data about the event (sometimes these properties are browser-specific, so it's recommended that you make use of the browser-equalizing methods of Y.Event to retrieve the appropriate values for properties such as target, relatedTarget, and charCode. All event handlers are called synchronously at each event target throughout the event's lifetime. Events are simulated using the simulate() method on any Y.Node instance. """

Comments

2

All of the major javascript libraries have the ability to trigger events. To add to the chorus of examples, in jquery you do it with: $("target_element").trigger("an_event");

Comments

1

You can use prototype.js to fire your own custom events

e.g. treeContainer.fire('nodeIcon:mousedown', {targetEvent: event, node: node});

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.