Fires a specified event on the object.
Syntax
bFired = object.fireEvent(sEvent [, oEventObject])
Parameters
sEvent Required. String that specifies the name of the event to fire. oEventObject Optional. Object that specifies the event object from which to obtain event object properties.
Return Value
Boolean. Returns one of the following values:
true- Event fired successfully.
false- Event was canceled.
Remarks
If the event being fired cannot be canceled, fireEvent always returns
true.Regardless of their values specified in the event object, the values of the four event properties— cancelBubble, returnValue, srcElement, and type—are automatically initialized to the values shown in the following table.
Event object property Value cancelBubble false returnValue true srcElement element on which the event is fired type name of the event that is fired
Example
The following sample shows how to use the fireEvent method.
<html> <head> <script type="text/javascript"> function fnFireEvents() { oDiv.innerText = "The cursor has moved over me!"; oButton.fireEvent("onclick"); } </script> </head> <body> <h1>fireEvent Method Sample</h1> <p>By moving the cursor over the <strong>div</strong> below, the button is clicked.</p> <div id="oDiv" onmouseover="fnFireEvents();"> Mouse over this! </div> <p><button id="oButton" onclick="this.innerText='I have been clicked!'">Button </button></p> </body> </html>Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/fireEventEX1.htm
Standards Information
There is no public standard that applies to this method.
Applies To
A, ABBR, ACRONYM, ADDRESS, APPLET, AREA, B, BASE, BASEFONT, BDO, BGSOUND, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, COMMENT, CUSTOM, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, FRAMESET, HEAD, hn, HR, HTML, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, INS, ISINDEX, KBD, LABEL, LEGEND, LI, LINK, LISTING, MAP, MARQUEE, MENU, nextID, NOBR, NOFRAMES, NOSCRIPT, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, RT, RUBY, S, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, STRONG, styleSheet, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TITLE, TR, TT, U, UL, VAR, WBR, XML, XMP, Element Constructor, HTMLDocument Constructor
See Also
createEventObject
Following GMariani's tip, I attached fireEvent to a paragraph element and tested it against the all of the event names IE recognizes. For 59 of the event names, fireEvent returned true. For the following 20 events names, fireEvent returned the Invalid Argument error:
onabort onafterprint onbeforeprint onbeforeunload onbounce onchange onerror onfinish onhashchange onload onmessage onoffline ononline onreset onselect onselectionchange onstart onstop onsubmit onunload
When I used fireEvent to trigger onmouseover, it returned false.
I've done some test with real mouse click on an client side image map. The event object generated from my click indicates (by the window.event.srcElement property) the event is generated from <area> tag. But when I tried to programmatically call the <area>'s fireEvent(), nothing happened!
Does IE actually support simulating click on a client side image map?
