views:

25

answers:

2

I have few anchors with a click event:

$$('.someanchor').invoke('observe', 'click', somefunction );

When the anchor is clicked, the browser scrolls to top. I tried to insert return false at the end of somefunction, but it still scrolls up.

Usually I would use something like:

Event.observe('somelement', 'click', somefunction, false);

But this doesnt work for a collection of elements. So how do I return false from a invoke statement?

+2  A: 

In somefunction, add the following at the end of the function body (make sure e is the last argument, and is used for the Event object):

e.preventDefault();
Delan Azabani
+1  A: 

"e.preventDefault()" prevents the anchor default behavior but not the event propagation (bubbling). I would use "Event.stop(event)" to neutralize both, just for being on the safe side.

Zaziffic