Return to Snippet

Revision: 21235
at December 7, 2009 14:30 by Jamie


Updated Code
// Method to fire DOM0 events such as onblur, onfocus, onchange
function fireEvent(element,event){
	if(document.createEvent){
		var evt = document.createEvent("HTMLEvents");
		evt.initEvent(event,true,true);
		return !element.dispatchEvent(evt);
	} else if(document.createEventObject) {
		var evt = document.createEventObject();
		return element.fireEvent('on'+event,evt);
	}
};

Revision: 21234
at December 7, 2009 14:08 by Jamie


Initial Code
Element.prototype.triggerEvent = function(eventName)
{
    if (document.createEvent)
    {
        var evt = document.createEvent('HTMLEvents');
        evt.initEvent(eventName, true, true);

        return this.dispatchEvent(evt);
    }

    if (this.fireEvent)
        return this.fireEvent('on' + eventName);
}

$('foo').fireEvent('mouseover');

Initial URL

                                

Initial Description

                                

Initial Title
DOM Level 0 "Fire Event"

Initial Tags

                                

Initial Language
JavaScript