JavaScript Cases: Collapsing Submenus JS


Menu Expand/Collapse Menu

The java script function for handling submenu expand/collapse 1st checks to see if the variable for the submenu name is null; if so the function does nothing.

If the submenu name is not null, the function checks to see if the current submenu is not the same as the last submenu opened; if so the old menu is collapsed before expanding the new submenu.

Then the status of the current menu is checked; if open, close. If closed, open.

Finally the menu is saved for comparison when the function is called again.

Code provided in screenshot for study only, hence no copy/paste.

This java script is adapted from Visual Quickstart Guide CSS, DHTML, and Ajax, Fourth Edition by Jason Cranford Teague.

JScript Cases