Can anyone point me to the documentation of the html Event object?
Bonus Reading
The only reason i know a global Event object exists is because it was mentioned in a Stackoverflow answer:
onclick="SomeEvent(this, event)"
function SomeEvent( el, event ) {
var target = event.srcElement || event.target;
if( el === target ) {
// run your code
}
}
Where it seems to have the properties:
srcElementtarget
Googling around i found W3 School’s page on the HTML DOM Event object, which lists the following properties:
bubbles: Returns whether or not an event is a bubbling eventcancelable: Returns whether or not an event can have its default action preventedcurrentTarget: Returns the element whose event listeners triggered the eventeventPhase: Returns which phase of the event flow is currently being evaluatedtargetReturns the element that triggered the eventtimeStampReturns the time (in milliseconds relative to the epoch) at which the event was created –typeReturns the name of the event
and methods:
initEvent(): Specifies the event type, whether or not the event can bubble, whether or not the event’s default action can be preventedpreventDefault(): To cancel the event if it is cancelable, meaning that any default action normally taken by the implementation as a result of the event will not occurstopPropagation(): To prevent further propagation of an event during event flow
It’s missing srcElement, so it’s safe to say it’s not complete documentation.
Then there’s Microsoft’s page on the event object. It doesn’t have any documentation; only mentioning the object. But it does mention that:
some properties might not have meaningful values during some events. For example, the
fromElementandtoElementproperties
W3Schools page doesn’t mention fromElement or toElement properties; so it’s not complete.
The MSDN page references a link to W3C:
Standards information
Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5
A search of that page contains no mention of fromElement or toElement.
So can anyone point me to documentation of the html Event object?
The MDN site provides very reliable information: https://developer.mozilla.org/en/DOM/event. Your
event.toElementproperty is a non-standard Microsoft thing, a quick test showedundefinedfor the property in Firefox:The correct property to use is
target. Also note thateventis not global, it is only a local variable. You are suggested to useaddEventListenerfor adding DOM events as described in the MDN page.quirksmode.org has nice tables on compatibility across browsers.
W3schools… well http://w3fools.com
Since you want to know more about the IE-specific
srcElementproperty, consult Microsofts documention. From srcElement property: