views:

1115

answers:

3

I want to create a link like this:

<a href="http://example.com"&gt;text&lt;/a&gt;

and replace the behavior so that the link downloads the content with Ajax instead when clicking.

It is important for me not to replace the href attribute (so copying the link still works).

One solution would be to do:

$('link').onclick = function() { return false; };

but I would like to use the .observe method. But this doesn't work:

$('link').observe('click', function() { return false; });

(which is quite logical).

Any ideas on how I could achieve this?

Thanks.

+3  A: 

You have to use the event object to achieve this with prototype.

$('link').observe('click', function(event) { event.stop() });
August Lilleaas
Yeah that's it!Thanks to everybody for the solution...
enyo
+1  A: 

Hello, did you try this ?

$('link').observe('click', function(e) { Event.stop(e); });

or

$('link').observe('click', function(e) { e.stop(); });

or

$('link').observe('click', Event.stop);
Fabien Ménager
A: 

Ho to enable it back?

imohan
I guess you could just stopObserving it.
enyo