Monday, 4 June 2018

Why the tab "My Ticekts" dont stay active when the url is "https://ift.tt/2JrrEVr" is acessed?

I have some list items in the "#registration_form_list" list. The default active list item is the list item with id "#generalInfo". But I want that when a url like this "http://proj.test/user/profile?user=1#myTickets" is accessed the tab that stays active is the "My Tickets" tab.

So I want to turn the tab active based on the current url. But its not working with the jQuery below.

Do you know why?

Html:

<ul class="nav nav-pills bg-light-gray registration_form_list" role="tablist">
    <li class="">
        <a class="nav-link active" href="#generalInfo" data-toggle="tab" role="tab">
            <i class="fa fa-user" aria-hidden="true"></i> <span class="d-none d-lg-inline-block">General Info</span></a>
    </li>
    <li class="disabled">
        <a class="nav-link" href="#myTickets" data-toggle="tab" role="tab">
            <i class="fa fa-calendar" aria-hidden="true"></i> <span
                    class="d-none d-lg-inline-block">My Tickets</span></a>
    </li>
    <!-- more list items -->
</ul>

jQuery:

   var path = window.location.href;

        $('.registration_form_list a').each(function () {
            var hash = $(this).attr('href').split('#')[1];
            //alert(hash);
            if (this.href === path) {
                $('.registration_form_list a').removeClass('active');
                $('a[href="#'+hash+'"]').addClass('active');
            }
        });

For example I have a method where the user is redirected to the "http://proj.test/user/profile?user=1#myTickets" but the tab that remains active is the "#generalInfo".

return redirect(route('user.index', ['user' => Auth::id()]).'#myTickets');



from Why the tab "My Ticekts" dont stay active when the url is "http://proj.test/user/profile?user=1#myTickets" is acessed?

No comments:

Post a Comment