Tutorials Point


  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

Prototype Event element() Method


previous next AddThis Social Bookmark Button


Advertisements

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>

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



previous next Printer Friendly

Advertisements


  

Advertisements