menu with dynamic submenu in javascript
<button onclick="SubMenu();">Create</button>
<ul>
<li><a href="#">Games</a>
<ul id="submenu"></ul>
</li>
<li><a href="#">Stake</a></li>
<li><a href="#">Max PLayers</a></li>
<ul>
Run code snippet
menu with dynamic submenu in javascript
<button onclick="SubMenu();">Create</button>
<ul>
<li><a href="#">Games</a>
<ul id="submenu"></ul>
</li>
<li><a href="#">Stake</a></li>
<li><a href="#">Max PLayers</a></li>
<ul>
Run code snippet
menu with dynamic submenu in javascript
var gameName=['Game one','Game Two','Game three']
function SubMenu(){
//Set variable for the submenu ul element
var Submenu = document.getElementById('submenu');
//For loop - for each value in the array
for(var i=0; i<gameName.length; i++){
//Create new li/List Item
var Item = document.createElement('li');
//Set innerHTML for this element
Item.innerHTML='<a href="#">'+gameName[i]+'</a>';
//Append new element to the submenu.
Submenu.appendChild(Item);
}
//---Demo use Only
document.getElementsByTagName("button")[0].remove();
//---
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us