Where to place "return false"; in jQuery function to fix page feed problem

Initially, I was looking for an answer to show / hide the problem with page transfer. Finding the answer here: the link with href = "#" scrolls up the page when used with jQuery slidetoggle , I need to figure out where to put return false in the following code:

 toggleDetail : function(obj) { $(obj).parent().parent().next().toggleClass('hide'); $(obj).text() == 'Show' ? $(obj).text('Hide') : $(obj).text('Show'); }, 

and here is my call to show / hide. "href =" javascript: void (0); "worked by stopping page skipping, do I still need" return false "?

 <a href="javascript:void(0);" onclick="VSASearch.toggleDetail(this)">Show</a> 

I tried adding "return false" to the end of every line of $(obj) before the semicolon, but that is not the case.

+4
source share
3 answers
 toggleDetail : function(obj) { $(obj).parent().parent().next().toggleClass('hide'); $(obj).text() == 'Show' ? $(obj).text('Hide') : $(obj).text('Show'); return false; }, 
+1
source

You just need to return false in the onclick handler. If onclick returns false, then reloading postback / page will stop.

 <a href="#" onclick="VSASearch.toggleDetail(this);return false;" /> 

Or you can return the result of your functions as follows:

 toggleDetail : function(obj) { $(obj).parent().parent().next().toggleClass('hide'); $(obj).text() == 'Show' ? $(obj).text('Hide') : $(obj).text('Show'); return false; }, 

from

 <a href="#" onclick="return VSASearch.toggleDetail(this);" /> 
+6
source

you want to return false from onclick binding

 <a onclick="VSASearch.toggleDetail(this); return false">Show</a> 

Even better, use unobtrusive javascript and assign an event handler in the $ () function:

 <a id="show">Show</a> .... $(function() { .... $("#show").click = function() { VSASearch.toggleDetail(this); return false; } 
+2
source

Source: https://habr.com/ru/post/1309128/


All Articles