Search code examples
jqueryajaxlaravel-5.3

Remaining on same Tab


i have a tab menu that has a different section within I.E to do list , file upload , notepad however when you for example add a task to the to do list on submit the page then refreshes back to Tab 1 when i want this to stay on the same tab

here is my current code for the tab menu

<div class="tab-content">
        <div class="tab-pane active" id="tabs-1">
            @include('includes/_tasks')
        </div>
        <div class="tab-pane" id="tabs-2">

        </div>
        <div class="tab-pane" id="tabs-3">
            @include('includes/_notes')
        </div>
        <div class="tab-pane" id="tabs-4">
            @include('includes/_file_upload')
        </div>
        <!--            <div class="tab-pane" id="tab5">
                        @include('includes/_github')
                    </div>-->
    </div>

Solution

  • You can temporary save the last active tab index in one object (Or you can use cookie as well) and after page refresh, you first find tab index from that object. If it contains any value then apply active class to that tab. Otherwise it will be on first tab by default.