Navigation for active css menu link not working

28 views Asked by At

I am using spring tiles and want my menu links to stay active when user clicks on it but it is not working and if i am using the js in the tile the tile will refresh it on load. here is my js

function myFunction(obj){
            var div = document.getElementById("menu-container");
            var anchor =div.getElementsByTagName('a');
            anchor[0].className="sidebar-item";
            anchor[1].className="sidebar-item";
            anchor[2].className="sidebar-item"
            anchor[3].className="sidebar-item";
            anchor[4].className="sidebar-item";
            anchor[5].className="sidebar-item";
            obj.className="sidebar-item active";
            alert(obj.className);
        }  

JSP

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<link href="<c:url value="/resources/menu.css" />" rel="stylesheet">
<script src="<c:url value="/resources/menu.css" />"></script>
<title>Insert title here</title>
</head>
<body>
    <div id="menu-container" style="width: 100%">
        <a class="sidebar-item" onclick="myFunction(this)" href="add"> Add Question</a>
        <a class="sidebar-item" onclick="myFunction(this)" href="search">Search Question</a>
        <a class="sidebar-item" onclick="myFunction(this)" href="update"> Edit Question</a>
        <a class="sidebar-item" onclick="myFunction(this)" href="delete"> Delete Question</a>
        <a class="sidebar-item" onclick="myFunction(this)" href="">Upload Json</a>
        <a class="sidebar-item" onclick="myFunction(this)" href="">Upload Csv</a>
    </div>
</body>
</html>
0

There are 0 answers