skip to Main Content

ok I search the forum before posting here & found many solution. unfortunately not a single one is working for me. I’m using latest bootsrap v3.3.5 & when ever I try to change my tabs the page jump to top & the content from the tab panel goes down.

<div id="featured-tabs">
<!-- Nav tabs -->
<ul class="list-inline" role="tablist">
<li role="presentation" class="active"><a href="#residential" aria-controls="residential" role="tab" data-toggle="tab" class="btn btn-theme-primary btn-lg">Residential</a></li>
<li role="presentation"><a href="#commercial" aria-controls="commercial" role="tab" data-toggle="tab" class="btn btn-theme-secondary btn-lg">Commercial</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="residential">
....content here
</div>
<div role="tabpanel" class="tab-pane fade" id="commercial">
....content here
</div>
</div>
</div>

& here is my js:

$('#featured-tabs ul.list-inline li a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
        history.pushState( null, null, $(this).attr('href') );
    })

so how I can solve this page jump problem for latest Bootstrap version?

2

Answers


  1. Check if you have jquery and bootstrap.js files before closing bod tag

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    

    You can use it without javascript as it says in bootstrap
    http://getbootstrap.com/javascript/#tabs

    just:

    <div>
    
      <!-- Nav tabs -->
      <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
        <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
        <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
        <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
      </ul>
    
      <!-- Tab panes -->
      <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="home">...</div>
        <div role="tabpanel" class="tab-pane" id="profile">...</div>
        <div role="tabpanel" class="tab-pane" id="messages">...</div>
        <div role="tabpanel" class="tab-pane" id="settings">...</div>
      </div>
    
    </div>
    

    here demo http://jsbin.com/vafetewawe/edit?html,output

    Login or Signup to reply.
  2. Try using this:

    $('#featured-tabs ul.list-inline li a').click(function (e) {
            e.preventDefault();
            e.stopImmediatePropagation();
            $(this).tab('show');
            history.pushState( null, null, $(this).attr('href') );
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search