Hola,
Este es un ejemplo:
Código javascript
:
Ver original<script type="text/javascript">
<!--
function $(id){return document.getElementById(id);}
function alertar(){
alert('Si!');
}
function detener(){
removeEvent.call($('prueba'),'click',alertar);
}
var addEvent=function(type, fn ) {
if ( this.addEventListener ) {
this.addEventListener( type, fn, false );
} else if(this.attachEvent){
var _this=this;
var f= function(){fn.call(_this,window.event);};
this.attachEvent( 'on'+type, f);
this[fn.toString()+type]=f;
}else{
this['on'+type]=fn;
}
};
var removeEvent=function(evType,fn){
if(this.removeEventListener){
this.removeEventListener(evType, fn, false);
}else if (this.detachEvent){
this.detachEvent("on"+evType, this[fn+evType+'n']);
this[fn+evType+'n']=null;
}else{
this['on'+evType]=function(){};
}
};
onload=function(){
addEvent.call($('prueba'),'click',alertar);
addEvent.call($('prueba'),'mouseout',detener);
};
-->
</script>
<div id="prueba" style="background-color:#CCCCCC; width:50px; height:50px;">Click!</div>
Gracias
Salu2