I have a javascript function which onclick changes the class style to li tag to active, but i am looking to reset the other li's if they are already set as active.
I am looking for a solution to loop through the li tags and check the id that has been clicked and if <> then chabge class to nothing else change to active.
Code:
<script language="JavaScript">
function change(id, newClass) {
identity=document.getElementById(id);
identity.className=newClass;
}
</script>
<ul>
<li id="111" class="">
<a href="#" onclick="change('111', 'active');">link</a>
</li>
<li id="222" class="">
<a href="#" onclick="change('222', 'active');">link</a>
</li>
</ul>
I am looking for a solution to loop through the li tags and check the id that has been clicked and if <> then chabge class to nothing else change to active.