Copyright © tutorialspoint.com

Prototype Event element() Method

previous next


Advertisements

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

Syntax:

Event.element();

Return Value :

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

Copyright © tutorialspoint.com