Event.observe(x[i],''mouseover'', _btnOver(), false);
Should be this:
Event.observe(x[i],''mouseover'', _btnOver, false);
When calling it with empty parentheses (_btnOver() vs _btnOver), the
function is called RIGHT THEN. If you leave off the parentheses, a
reference to the function is passed, and then the function reference is
used whenever the event fires.
Hope that helps.
Greg
P.S. The original code will not work in Mozilla-based browsers, unless
something has changed since I last wrote event handling code manually
(Mozilla uses the DOM addEventListener function, which personally I
think is lame. IE''s way makes more intuitive sense and the W3C was
just
sticking it to Microsoft by inventing a new scheme that was totally
incompatible, but I digress).
-----Original Message-----
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of Marco
M. Jaeger
Sent: Tuesday, November 08, 2005 2:33 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] Event.observers - I''m totally list - please
help
Hello,
I need some help on how to use the Event.observers - thank you in
advance
for your input.
<div class="navcontainer">
<ul id="nav">
<li class="button">
<img src="images/spacer.gif" width="20"
height="20">
</li>
<li class="button">
<img src="images/spacer.gif" width="20"
height="20">
</li>
</ul>
</div>
I have a little unordered list like the one above.
This is the code that is working:
/* navigation bar */
var x = $(''nav'').getElementsByTagName(''LI'');
for (var i = 0; i < x.length; i++) {
if (x[i].className == ''fm-navbtnUp'') {
x[i].onmouseover = _btnOver;
}
}
function _btnOver() {
alert(this.nodeName);
}
This is the prototype way:
/* navigation bar */
var x = $(''nav'').getElementsByTagName(''LI'');
for (var i = 0; i < x.length; i++) {
if (x[i].className == ''fm-navbtnUp'') {
Event.observe(x[i],''mouseover'', _btnOver(), false);
}
}
function _btnOver(event) {
var elm = Event.element(event);
alert(elm.nodeName);
}
The prototype way either returns the LI or the IMG tag depending on how
fast
I move over the image inside the li tag.
Am I using the Event.observer the wrong way or what is the problem. How
do I
have to set this up in order to make it work?
Once again, thank you for your input.
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it''s
FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs