Tutorials Point

  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

Prototype fire() Method

previous next AddThis Social Bookmark Button


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.


element.fire(eventName[, 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 custome event


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

<title>Prototype examples</title>
<script type="text/javascript" 

document.observe("widget:frobbed", function(event) {
   alert("Element with ID (" + event.target.id +
   ") frobbed widget #" + event.memo.widgetNumber + ".");

function showResult(){
   someNode = $('firstDiv');
   someNode.fire("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" 


To understand it in better way you can Try it yourself.

previous next Printer Friendly