Search code examples
javascriptdom-events

How to Fire Personal Event in JavaScript


I can't fire personal events using JavaScript in IE. In Firefox work great.

My code is:

var evento; 
if(document.createEventObject)  
{  
   evento = document.createEventObject();  
   document.fireEvent('eventoPersonal', evento);     
}  
//FF  
else  
{  
    evento = document.createEvent('Events');  
    evento.initEvent('eventoPersonal',true,false);  
    document.dispatchEvent(evento);  
}

But when try to execute document.fireEvent('eventoPersonal', evento); in IE, it doesn't work. How can I fire NO custom events in IE?

In Internet Explorer I get the error: "Invalid arguments" in the line where execute document.fireEvent('eventoPersonal', evento);


Solution

  • You may want to consider using a library to abstract this. Both prototype an jquery will handle this for you. Jquery is especially good at allowing you to create an event with very simple code.

    Jquery's documentation is available here: http://docs.jquery.com/Events