Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So basically I have a sidebar menu mapped like this
(Please be informed that this is not a treeview but rather a sidebar menu using SB-Admin2):

*Parents
    List
    Details
*Students
    List
    Details
    Grades
    Creadentials


Parents / Students (Level 1 Menu)
List / Details / Grades / Credentials (Level 2 Menu)

I wanted to add class on Level 1 Menu when I click on Level 2 Menu.
Your help would be greatly appreciated.
:)
Posted

1 solution

<li id="level2List" onclick="markLevel1();">List</li>


function markLevel1() {
    $("#level2List").parent.parent.addClass("yourClass")
}


This solution assumes the following menu structure and the use of jQuery
<ul>
    <li>level 1
        <ul>
            <li>level 2</li>
        </ul>
    </li>
</ul>


This could be improved or generalized by using class instead of id, use of $(this) within the function and/or naming the parent so you could use .closest("selector") function from jQuery.

Adjust to your particular menu stucture
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900