hey how r you ? please check this, its a simple jquery.
// scroll back to top btn
$('.scrolltop').click(function(){
$("html, body").animate({ scrollTop: 0 }, 1000);
return false;
});
this code is used to scroll top of a page slowly, i like it just one thing i dont understand why they use return false ? is it a good practice ? if yes then why ? i cut that but it still works without writing return false. i have seen this return true or false in many codes but i dont understand why they are used. will you please help me to know ?
It's commonly used on click functions to stop the browser for doing its default behaviour.
For example, if your .scrolltop element was an anchor tag, you'd have to put # as its href which would append the # to the URL. That's not really what we want for the user to experience, so we make it not happen by returning false at the end up the function.
hey how r you ? please check this, its a simple jquery.
// scroll back to top btn $('.scrolltop').click(function(){ $("html, body").animate({ scrollTop: 0 }, 1000); return false; });this code is used to scroll top of a page slowly, i like it just one thing i dont understand why they use return false ? is it a good practice ? if yes then why ? i cut that but it still works without writing return false. i have seen this return true or false in many codes but i dont understand why they are used. will you please help me to know ?
It's commonly used on click functions to stop the browser for doing its default behaviour.
For example, if your
.scrolltopelement was an anchor tag, you'd have to put#as itshrefwhich would append the#to the URL. That's not really what we want for the user to experience, so we make it not happen by returning false at the end up the function.This is not the best practice, though. For more info, this article is good reading: http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/
Thank you doc.
great article doc thanks for sharing