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>

No comments:

Post a Comment

Thank You For Your Great Contribution

Featured Post

how to post formdata or http.context.form data from angular 6 to asp.net mvc web api or api using Token based authentication with header

how to post formdata or http.context.form data from angular 6 to asp.net mvc web api or api using Token based authentication with header  ...

Popular Posts