How To Create Menu Active link Using java script in website



How To Create Menu Active link Using java script in website 



<script>
        function onCancel() {
            window.location.href = "/Home/Index";
        }

        $(function () {
            setNavigation();
        });

        function setNavigation() {
            var path = window.location.pathname;
            path = path.replace(/\/$/, "");
            path = decodeURIComponent(path);

            $(".sidebar-menu a").each(function () {
                var href = $(this).attr('href');
           
                if (path.substring(0, href.length) === href) {
                    $(this).parents('li').parents('li').addClass('active');
                    var path1 = path.split('/');
                    var heref1 = href.split('/');
                    if (path1[2] === heref1[2]) {
                        $(this).parents('li').addClass('active');
                    }
                }
               
            });
        }
    </script>

1 comment:

  1. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks hospedaje web compartido

    ReplyDelete

Thank You For Your Great Contribution

Featured Post

how to find n number of nodes have child or cildren

 how to find n number of nodes have child or cildren for that we use recursive function  const   data = {     'id' : '0' ,...

Popular Posts