Sunday, August 05, 2007

prototype javascript library event observe example

<div id="d1">
<a href="" id="a1" target="_blank" onclick="testEvent(event); return false;"></a>
<a href="" id="a2" target="_blank"></a>
<a href="" id="a3" target="_blank" onclick="alert(this); return false;"></a>
<script type="text/javascript" charset="utf-8">
function testEvent(event) {
var e = Event.element(event);
alert(Event.findElement(event, 'div').id);

/*for(var p in Event){
doc('Event["' + p + '"] = ' + Event[p]);

var handler = function (e) {
Event.stop(e); // prevent pop window to

Event.observe('a2', 'click', handler, true);
Event.stopObserving('a2', 'click', handler, true); // cancel observe , click will pop window to

No comments :