click link on bottom of the page taking to top of the page

161 Views Asked by At

I have a link in a page which is a rails link_to_remote. when i click on that link its taking me to top of the page with '#' in url. How can i avoid that?

= link_to_remote "#{stream_thank_yous_count}" ,:url => add_thankyou_stream_path(stream), :method => :get, :before => "event.preventDefault();", :after => "$('ajaxLoaderDiv').hide();", :html => {:class => "icon-smile-o #{get_count_class(stream_thank_yous_count)}"}

HTML generated for this is

<a id="fav_980209445" class="icon-heart fav" onclick="new Ajax.Request('/streams/980209445/mark_as_favourite?social_inbox=false', {asynchronous:true, evalScripts:true, method:'get', parameters:'authenticity_token=' + encodeURIComponent('tHMWDh7R1GZ2t43ejt5aGF4Rds7Jx2nV386JVs5x8wo=')}); $('ajaxLoaderDiv').hide();; return false;" href="#">0</a>

I tried replacing the href with javascript:void(0). using

$j("a.icon-smile-o,a.icon-heart").attr("href", "javascript:void(0)");

But failed to acheive. Can anyone help me how to fix this please.

2

There are 2 best solutions below

2
On BEST ANSWER

try this one:

$("a.icon-smile-o,a.icon-heart").click(function(e){
    e.preventDefault();
});
0
On
return false;

return false; at the end of the processing document so that the document will not return anything and just passes the value