I am using the W3.CSS animated drop-down (https://www.w3schools.com/w3css/w3css_dropdowns.asp).
But I cannot figure out how can I populate the menu items dynamically according to a list of item names.
I guess some Javascript should be involved here, so I try in this forum
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<div class="w3-dropdown-click">
<button onclick="showMenu()" class="w3-button">Team1</button>
<div id="Demo" class="w3-dropdown-content w3-bar-block w3-animate-zoom">
<a href="#" class="w3-bar-item w3-button">Link 1</a>
<a href="#" class="w3-bar-item w3-button">Link 2</a>
<a href="#" class="w3-bar-item w3-button">Link 3</a>
</div>
</div>
<script>
async function getTeams() {
try{
(async () => {
const response = await fetch('http://localhost:8088/teams')
var teamsArrObj = await response.json()
console.log(teamsArrObj);
return teamsArrObj;
})()
}catch{
console.log("error");
}
}
function showMenu() {
var x = document.getElementById("Demo");
if (x.className.indexOf("w3-show") == -1) {
x.className += " w3-show";
} else {
x.className = x.className.replace(" w3-show", "");
}
}
</script>
Thanks!