Website Building » Wix » How Do I Create a Collapsible Menu in Wix?

How Do I Create a Collapsible Menu in Wix?

Last updated on January 9, 2023 @ 2:42 pm

Creating a collapsible menu in Wix is a simple process that can be accomplished by following a few easy steps. First, create a new menu item in the left sidebar of your Wix Editor. Then, click on the “Add Page” link in the top menu bar and select “New Page.” This will open a new page in the Wix Editor.

Next, click on the “Add” link in the top menu bar and select “HTML.” This will open the HTML code editor. Paste the following code into the HTML code editor:

GREAT NEWS:

Exciting update! We've collaborated with Wix to offer WBI users with a free plan for all website creation needs - Explore the details here.

<script type="text/javascript">function toggleMenu(objID) {
if (document.getElementById(objID).style.display == "none") {
document.display = "block";
} else {
document.display = "none";}}
</script>
<a href="javascript:toggleMenu('sub1')">+Sub Menu 1</a> <div id="sub1" style="display:none"> <a href="#">Sub Menu Item 1</a> <a href="#">Sub Menu Item 2</a> <a href="#">Sub Menu Item 3</a> </div> <a href="javascript:toggleMenu('sub2')">+Sub Menu 2</a> <div id="sub2" style="display:none"> <a href="#">Sub Menu Item 1</a> <a href="#">Sub Menu Item 2</a> <a href="#">Sub Menu Item 3</a> </div>

The code above will create two collapsible menus, each with three submenu items. You can add as many submenu items as you like by copying and pasting the code above and changing the number in the “id” attribute of the <div> tag. For example, if you want to add a fourth submenu item to “Sub Menu 1,” you would change the code to this:

<script type="text/javascript">function toggleMenu(objID) {
if (document.display == "none") {
document.display = "block";}
else {document.display = "none";}}
</script>

<a href="javascript:toggleMenu('sub1')">+Sub Menu 1</a>

<div id="sub1" style="display:none">
<a href="#">Sub Menu Item 1</a>
<a href="#">Sub Menu Item 2</a>
<a href="#">Sub Menu Item 3</a>
<a href="#">Sub Menu Item 4</a>
PRO TIP: While Wix is a popular website builder, it is not recommended for use with a collapsible menu. This is because Wix does not support the HTML5 code necessary for a collapsible menu to function properly. Additionally, Wix does not allow for the easy customization of website code, making it difficult to add a collapsible menu to your site without extensive coding knowledge.
Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.