I have a page with multiple tabs and i Show and hide them based on a href click using jquery. Whenever I click on "a href", the page is scrolled down. Am trying to set the focus on the top of the page. This is my first project in Jquery. I tried the following but still doesnt work.
please do share some light on that matter.
Try like this:
$(".gototop").click(function(){
var focusElement = $("#contents");
$(focusElement).focus();
ScrollToTop(focusElement);
});
function ScrollToTop(el) {
$('html, body').animate({ scrollTop: $(el).offset().top - 50 }, 'slow');
}
Just use <a href="#">Your link</a>. It will take you to the top of the page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With