Prototype - fire() Method


This method is used to fire a custom event with the current element as its target.

The custom event has all the same properties and methods of native events. Like a native event, it will bubble up through the DOM unless its propagation is explicitly stopped.

Custom events are dispatched synchronously: Element#fire waits until the event finishes its life cycle, then returns the event itself.

Syntax[, memo]);

The optional second argument will be assigned to the memo property of the event object so that it can be read by event handlers.

Return Value

It returns custom event


In this example, an element with ID (firstDiv) frobbed widget #19.

      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
         document.observe("widget:frobbed", function(event) {
            alert("Element with ID (" + +
               ") frobbed widget #" + event.memo.widgetNumber + ".");
         function showResult() {
            someNode = $('firstDiv');
  "widget:frobbed", { widgetNumber: 19 });

      <p>Click the button to see the result.</p>
      <div id = "firstDiv">
         <p>This is first paragraph</p> 
      <br />
      <input type = "button" value = "showResult" onclick = "showResult();"/>