Prevent auto scrolling when clicking tab anchor
Posted
by
JohnCrossy
on Stack Overflow
See other posts from Stack Overflow
or by JohnCrossy
Published on 2012-11-29T16:26:23Z
Indexed on
2012/11/29
17:04 UTC
Read the original article
Hit count: 191
On my page I have some tabs that I've added some javascript so when they're clicked the page loads the tab's anchor URL instead of simply changing the view with AJAX, but I now want to stop the browser from auto scrolling to the anchor location.
Having done some research, I'm pretty sure I just need to add a couple of lines so that when clicked it returns false or prevents default but, being a noob, I've no idea where to put them!?!
I know it's cheeky, but if any answers could include the full script (ie. the below) with the solution, that way I'll understand better and hopefully learn some valuable lessons also :)
Here's the code I'm using:
jQuery( function() {
jQuery('.ui-tabs').bind( 'tabsselect', function( e, ui ) {
window.location.hash = ui.tab.hash });
});
© Stack Overflow or respective owner