Prototype - Event element() Method



This method returns the DOM element on which the event occurred.

Syntax

Event.element();

Return Value

Returns the DOM element on which the event occurred.

Example

Here's a simple code that lets you click everywhere on the page and, if you click directly on paragraphs, hides them.

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         // Register event 'click' and associated call back.
         Event.observe(document, 'click', respondToClick);
  
         // Callback function to handle the event.
         function respondToClick(event) {
            var element = event.element();
            alert("Tag Name : " + element.tagName );
            
            if ('P' == element.tagName) {
               element.hide();
            }
         }
      </script>
   </head>

   <body>
      <p id = "note"> Click on any part to see the result.</p>
      <p id = "para">This is paragraph</p>
      <div id = "division">This is divsion.</div>
   </body>
</html>

Output

prototype_event_handling.htm
Advertisements