Reputation: 61
I use this script:
(function() {
var tabContainers = $('div.tabs > div');
tabContainers.hide().filter(':first').show();
$(window).bind('hashchange', function () {
var hash = window.location.hash || '#first';
tabContainers.hide();
tabContainers.filter(hash).show();
$('div.tabs ul.tabNavigation a').removeClass('selected');
$('a[href=' + hash +']').addClass('selected');
});
$(window).trigger("hashchange");
});
This part of code gives me everything that i need. To open the tab from the external page i use "index.php#first" href, for example. It opens the page with tabs with the exact tab opened, but it jumps to the anchor, and i need to show the page from it's top.
Does anybody know, how to prevent anchor jumps for this code?
Upvotes: 6
Views: 1346
Reputation: 6528
Have you tried doing a return false
inside the hashchange function?.
Otherwise, you can avoid using real IDs on your elements. That way it will not scroll.
Update:
As you are using jQuery you can also try with: e.preventDefault
. The function will need to receive e
as parameter
Upvotes: 2