Expand Collapse Sidebar Navigation Dynamically

JavaScript Expand Collapse Style functionality for the sidebar navigation can be created by using JavaScript DOM style properties. In this sample Display property of style object of JavaScript DOM has been used to expand or collapse the DIV element dynamically.

JavaScript DOM Features Used

1. document object

2. getElementById method

3. style object

4. display property

 

Display property value "none" releases the white space occupied by the Div element.

 

The sample includes the CSS code to provide the interactive look and physical design to the output. In the header section of the HTML page JavaScript code has been added to perform the requried functionality. An input type HTML form button has been used to raise the click event that calls the JavaScript function that expands/collapses the sidebar navgation control created using HTML Div element. Try the sample below to learn and practice the JavaScript DOM code for developing this functionality:

 

Edit this code and click update to view output
OUTPUT:
  • HIRE EzineASP.Net Developers