Tutorials Point

  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

Prototype Event stopObserving() Method

previous next AddThis Social Bookmark Button


This method unregisters an event handler.

This function is called with exactly the same argument semantics as observe. It unregisters an event handler, so the handler is not called anymore for this element+event pair.


Event.stopObserving(element, eventName, handler
                             [, useCapture = false])

Here is explanation about passed parameters:

  • element: The DOM element you want to observe; as always in Prototype, this can be either an actual DOM reference, or the ID string for the element.

  • evenetName: The standardized event name, as per the DOM level supported by your browser. This includes click, mousedown, mouseup, mouseover, mousemove and mouseout.

  • handler: This is the event handler function. This can be an anonymous function you create on-the-fly.

  • useCapture: Optionally, you can request capturing instead of bubbling. The details are in the DOM Level 2 Events

Return Value :

  • NA


This example shows how it reacts only once click and after that programm stops observing.

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

// Register event 'click' and associated call back.
Event.observe(document, 'click', respondToClick);
// Callback function to handle the event.
function respondToClick(event) {
  alert("Left button is pressed...." );
  Event.stopObserving(document, 'click', respondToClick);


   <p id="note">Click anywhere to see the result.</p>

   <p id="para1">This is paragraph 1</p>

   <p id="para2">This is paragraph 2</p>

   <div id="division">
       This is divsion.


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

previous next Printer Friendly