srcElement Property
Gets or sets the object that fired the event.
Syntax
[ oObject = ] object.srcElement
Possible Values
oObject Object that specifies or receives the event that fired. The property is read/write. The property has no default value.
DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are supported in IE7 Standards mode and IE5 (Quirks) mode only. For more information, see About Dynamic Properties and Defining Document Compatibility.
Remarks
The property is read-only in Microsoft Internet Explorer 4.0, and read/write in Internet Explorer 5 and later.
Example
This example uses the srcElement property to retrieve the parent object, if needed, create the text range, move to the original object, and select the first word in the object.
<SCRIPT LANGUAGE="JScript"> function selectWord() { var oSource = window.event.srcElement ; if (!oSource.isTextEdit) oSource = window.event.srcElement.parentTextEdit; if (oSource != null) { var oTextRange = oSource.createTextRange(); oTextRange.moveToElementText(window.event.srcElement); oTextRange.collapse(); oTextRange.expand("word"); oTextRange.select(); } } </SCRIPT>
Standards Information
There is no public standard that applies to this property.
Applies To
event, Event Constructor
(There is no event.handlingElement property, and handling functions see 'this' empty.)
BUG. A null return value from srcElement.parentElement.id is not a null but an error ('hole') that crashes getElementById() and discontinues event-handling.
- 7/22/2009
- Mr. Raymond Kenneth Petry
- 8/3/2009
- Mr. Raymond Kenneth Petry
[N.B. MSIE onselectionchange event.srcElement is "null", too. Ray.]
<script>
function tr_onclick(evt)
{
var srcElement = evt.srcElement ? evt.srcElement : evt.target;
alert(srcElement.tagName);
}
</script>
HTML: <tr style="cursor:pointer" onclick="tr_onclick(event);"><th>Click Here</th></tr>
[jsudds.MSFT] That's correct. There are many properties that are not shared between the two implementations of the event object. You need to be careful to test your application in both browsers when using event properties, or use a event library to hide the differences from your code.
http://developer.mozilla.org/en/docs/DOM:event