Leave a li menu with active treeview after page reload

0

I have a menu in a Sidebar using <li> and <ul> , when I click on some the page is updated, because I use a <a> link in my.

I'm using the following javasscript to update the active menu:

    $('li').each(function () {
    if (window.location.href.indexOf($(this).find('a:first').attr('href')) > -1) {
        $(this).addClass('active').siblings().removeClass('active');
    }
});

This template works well for the%% normal, but when I have a

Like this:

<li class="treeview">
    <a href="#">
        <i class="fa fa-group" style="color:#4b676f"></i> <span>Partners</span>
        <span class="pull-right-container">
            <i class="fa fa-angle-left pull-right" ></i>
        </span>
    </a>
    <ul class="treeview-menu">
        <li>
            <a href="@Url.Action("Index", "Parceiro" , new { Area="Unidade" })"><i class="fa fa-list" style="color:#4b676f"></i> <span>List Partners</span></a>
        </li>
        <li>
            <a href="@Url.Action("NovoParceiro", "Parceiro" , new { Area="Unidade" })"><i class="fa fa-plus" style="color:#4b676f"></i> <span>Register a new Partner</span></a>
        </li>
    </ul>
</li> 

It does not change <li> it returns to default, I would like to know how to make this item active. I saw several answers but I could not understand any of them.

here's how my page is:

 <li style="margin-top:45px;font:normal" class="active"><a [email protected]("Index", "Dashboard" , new { Area="Unidade" })><i class="fa fa-bar-chart" style="color:#4b676f"></i> Statics and Reports</a></li>
    <li>
        <a href="@Url.Action("Index", "Informacoes" , new {Area="Unidade" })"><i class="fa fa-home" style="color:#4b676f" ></i> <span> Falcon Company</span></a>
    </li>
    <li>
        <a href="@Url.Action("Index", "Agendamento" , new {PaginaAtual = 0 , Area="Unidade" })"><i class="fa fa-calendar" style="color:#4b676f"></i> <span>Jobs Schedule</span></a>
    </li>
    <li class="treeview">
        <a href="#">
            <i class="fa fa-stethoscope" style="color:#4b676f"></i> <span>Employee</span>
            <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
            </span>
        </a>
        <ul class="treeview-menu">
            <li><a [email protected]("Index", "Profissional" , new {PaginaAtual = 0 , Area="Unidade" })><i class="fa fa-list" style="color:#4b676f"></i> List Employees</a></li>
            <li><a [email protected]("NovoProfissional", "Profissional" , new { Area="Unidade" })><i class="fa fa-plus" style="color:#4b676f"></i>Register a new Employee</a></li>

        </ul>
    </li>
    <li class="treeview">
        <a href="#">
            <img src="~/Content/imagens/IconesDashboard/dashboard.png" style="height:13px;margin-right:9px"> <span>Client</span>
            <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
            </span>
        </a>
        <ul class="treeview-menu">
            <li><a [email protected]("Index", "Empresa" , new {PaginaAtual = 0 , Area="Unidade" })> Client List</a>
            <li><a [email protected]("NovaEmpresa", "Empresa" , new { Area="Unidade" })>Register a new Client</a></li>
            @*<li><a [email protected]("Index", "Dashboard" , new { Area="Unidade" })> Outras Informacoes</a></li>*@
        </ul>
    </li>
    <li class="treeview">
        <a href="#">
            <i class="fa fa-group" style="color:#4b676f"></i> <span>Partners</span>
            <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right" ></i>
            </span>
        </a>
        <ul class="treeview-menu">
            <li>
                <a href="@Url.Action("Index", "Parceiro" , new { Area="Unidade" })"> <span>List Partners</span></a>
            </li>
            <li>
                <a href="@Url.Action("NovoParceiro", "Parceiro" , new { Area="Unidade" })"></i> <span>Register a new Partner</span></a>
            </li>
        </ul>
    </li> 
    
asked by anonymous 31.01.2017 / 18:36

1 answer

0

You will have to save this information in the client's browser (either by cookies, or by localStorage, or by some acceptable way) and when you load the page check if this preference exists and if yes, then select the value that is equal to the information recorded.

    
31.01.2017 / 19:33