createEventObject Method

Internet Development Index

Generates an event object for passing event context information when using the fireEvent method.

Syntax

oNewEvent = document.createEventObject( [oExistingEvent])

Parameters

oExistingEvent Optional. Object that specifies an existing event object on which to base the new object.

Return Value

Returns an event object.

Example

The following sample shows how to use the createEventObject method with the fireEvent method.

<html>
<body>
<script>
function OuterClick() {
if(event.expando == "from_inner")
{
alert("Event actually fired by clicking on inner DIV!")
}
else
{
alert("Event fired by clicking on outer DIV!")
}
}
function InnerClick() {
var eventObj = document.createEventObject();
// Set an expando property on the event object. This will be used by the
// event handler to determine what element was clicked on.
eventObj.expando = "from_inner";
parent.document.all.Outer.fireEvent("onclick",eventObj);
event.cancelBubble = true;
}
</script>
<div id="Outer" onclick="OuterClick()" style="height:200;width:200;padding:50;background-color:mistyrose">
<div id="Inner" onclick="InnerClick()" style="height:100;width:100;padding:25;background-color:lavender"></div>
</div>
</body>
</html>

Standards Information

There is no public standard that applies to this method.

Applies To

document