> elem.attachEvent("mousemove",mousemove)????? Isn't the DOM event
> "onmousemove"?
The W3C DOM Level 2 Events lists events named 'mousemove' or 'mouseover'
and _not_ 'onmousemove' or 'onmouseover'.
<http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MouseEvent>
attachEvent is not a method defined by the W3C DOM Level 2 Events (which
Mozilla supports), it is only part of the IE (5 and later) event API
(which Mozilla does not support). MSDN (for IE !) lists stuff like
'onmousemove' or 'onmouseover' as event names to be passed to attachEvent:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/attachevent.asp>
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/events.asp>
If you are scripting for Mozilla or any other browser supporting the W3C
DOM Level 2 Events module then you want e.g.
elem.addEventListener(
'mousemove',
function (evt) {
// handle event here in listener body
},
false
);
--
Martin Honnen
http://JavaScript.FAQTs.com/
I guess this is just more proof that the W3C is run by a bunch of
programmer-haters. Why else use a different name for an event when
attaching to it?
Another question... Why doesn't FF support attaching to events via
XHTML? If I do this:
<div id='foo' onmouseover='foomouse()'></div>
<script blahblah>
function foomouse(e)
{
alert(e);
}
</script>
in FF, e is shown to be "undefined". However, if I remove the event
handler from the declaration of the foo div and attach it (in the
onload event of the body) via addEventListener, e is no longer
undefined (alert shows "onmouseover"). Switching the xhtml to
'foomouse' or 'foomouse(e)' doesn't work either. Is there any sane
reason for doing this, other than to drive me batty? Even if the W3C
DOM specs doesn't support attaching to events in the xhtml, wouldn't
supporting that make life much easier for everybody? As of now, I have
to bind to all events in the onload event of the body. Which I bind to
in xhtml, ironically. Seems pretty lame to me. What am I missing?
I count the days until the whole lot is thrown out and replaced with a
sane standard, developed by professional programmers and designers
(four members, with one professional technical writer to document it).
Web UI design is just a friggin mess right now.
> I guess this is just more proof that the W3C is run by a bunch of
> programmer-haters. Why else use a different name for an event when
> attaching to it?
The event name is 'mousemove' and has been that even before the W3C DOM
standardized. Even with IE if you look at event.type it says e.g.
'mousemove' and _not_ 'onmousemove'.
An event handler is different from the event itself, event handlers
added as attributes in markup have traditionally been named
'on<eventname>' e.g. 'onmousemove'.
> Another question... Why doesn't FF support attaching to events via
> XHTML? If I do this:
>
> <div id='foo' onmouseover='foomouse()'></div>
Whether you use HTML or XHTML if the event handler is specified in the
(X)HTML markup then the event object is accessible as |event| in the
event handler e.g.
<div onmousemove="foomouse(event);">