Search
 
SCRIPT & CODE EXAMPLE
 

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();
//---
}
Comment

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript detect if active element is writable 
Javascript :: convert .js file to ts 
Javascript :: symfony iterate over entity 
Javascript :: router.put method 
Javascript :: decode jwt token online 
Javascript :: js if on cellular network 
Javascript :: auto linting and testing in react tyescript 
Javascript :: onClick: share image on Facebook angular 9 
Javascript :: how to convert javascript to typescript angular 
Javascript :: on page navigate event javascript 
Javascript :: how-can-i-implement-joi-password-complexity-in-joi-validation 
Javascript :: javascript dom functions 
Javascript :: pass a callback funcion into an async function node js 
Javascript :: how to put condition on pagination material table 
Javascript :: react-folder tree example 
Javascript :: filter by last week 
Javascript :: conditional ternary statement only one return 
Javascript :: javascript llop array 
Javascript :: angularjs How to set code view as deafult instead of tree in jsoneditor 
Javascript :: Angularjs to Angular Migration: factory prototype 
Javascript :: Presenting backend data using AngularJS/AJAX in MVC VIEW 
Javascript :: React Native Swift Escaping closure 
Javascript :: mutexify 
Javascript :: in node.js with express how to remove the query string 
Javascript :: jquery call service 
Javascript :: json query rails c 
Javascript :: queryselector undefined not working in react js 
Javascript :: jquery show loader 
Javascript :: Declaring A Internal Method Of A Class 
Javascript :: routing/switches 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =