I am very familiar with conditionally hiding or displaying elements when using Angular. I am less familiar with doing so with straight HTML and JS. I have an HTML page that makes use of twitter-bootstrap 3.4.0. With this HTML page I initially want to display one master drop-menu. Then, depending on what selection a user makes, I want to conditionally display one of several secondary drop-menus. This is my master drop-menu HTML:
<div class="dropdown">
<button class="btn btn-default btn-primary dropdown-toggle" type="button" data-toggle="dropdown"
onclick="loadCategoryList()">
Select Job Category
<span class="caret"></span>
</button>
<ul class="dropdown-menu" id="selectCategory"></ul>
</div>
And here's the JS being referenced:
let selectCat = document.getElementById("selectCategory");
// Load category list into drop-menu
async function loadCategoryList() {
const categoryArr = ["option 1", "option 2", "option 3", "emailer"];
while (selectCat.firstChild) {
selectCat.removeChild(selectCat.firstChild);
}
for (let i = 0; i < categoryArr.length; i++) {
let opt = categoryArr[i];
let a = document.createElement("a");
a.textContent = opt;
a.setAttribute('href', '#');
a.setAttribute('class', 'btn btn-link');
let li = document.createElement("li");
li.appendChild(a);
selectCat.appendChild(li);
}
}
Then I have a secondary drop-menu div node that looks like this:
<div class="dropdown">
<button class="btn btn-default btn-primary dropdown-toggle" type="button" data-toggle="dropdown"
onclick="loadEmailersList()">
Select Email Type
<span class="caret"></span>
</button>
<ul class="dropdown-menu" id="selectEmailer"></ul>
</div>
The change I want to make is I that I only want to display this secondary "emailer" div node if the selection from the master category list drop-menu was "emailer". In other words, the "emailer" drop-menu node should be hidden, and only become visible if and when the selection from the master category-list drop-menu is equal to "emailer".
I'm unclear how much of this happens in the HTML vs in the JS. How do I accomplish this using HTML, JS and Bootstrap?