Suneth Kalhara
Suneth Kalhara

Reputation: 1208

jQuery Tabs Selected Tab Prevent Jump to top

I'm using jQuery tabs, an click on a tab it add hash to the url

jQuery( "#tabs").tabs({
        activate: function(event, ui) {
            window.location.hash = ui.newPanel.attr('id');
        }
    });

problem is when i click on a tab it opens but it scroll and jump to top of the page

Normal tabsenter image description here

When i click on tab enter image description here

Anyone know how to fix this issue

Upvotes: 0

Views: 423

Answers (1)

User863
User863

Reputation: 20039

Try using history.pushState(). Check History Api docs

jQuery( "#tabs").tabs({
    activate: function(event, ui) {
        history.pushState(null, null, '#' + ui.newPanel.attr('id'));
    }
});

Upvotes: 2

Related Questions