Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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();
//---
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #menu #dynamic #submenu #javascript
ADD COMMENT
Topic
Name
5+6 =