After trying out @prettyInPink's suggested solution, I crafted my own non-jQuery alternative.
You can place this JavaScript snippet anywhere in your file (I believe)--currently, it resides in the header section.
<script type="text/javascript" >
function ModifyDropdowns(select_xx)
{
debug_mode = false;
menu_array = document.getElementsByClassName("state");
if (debug_mode) { menu_string = "<?php echo 'header-games.php:ModifyDropdowns - '.__LINE__; ?>" + ":\n\n" + "select_xx = " + select_xx + "\n" + "menu_array.length = " + menu_array.length + "\n"; }
if (select_xx.slice(0, 6) == "select") { country_str = select_xx.slice(-2); }
else { country_str = select_xx.slice(0, 2); }
for (counter=0; counter<menu_array.length; counter++)
{
if (debug_mode)
{
menu_string += "country_str = " + country_str + " - ";
menu_string += "menu_array["+ counter + "].id.slice(-2) = " + menu_array[counter].id.slice(-2) + "\n";
menu_string += "menu_array[" + counter + "] = " + menu_array[counter].id;
} // if (debug_mode)
if (country_str == menu_array[counter].id.slice(-2))
{
document.getElementById(menu_array[counter].id).style.display="flex";
if (debug_mode) { menu_string += " - displaying" + "\n"; }
} // if (("states_" + select_xx) == menu_array[count].id)
else
{
document.getElementById(menu_array[counter].id).style.display="none";
if (debug_mode) { menu_string += " - hiding" + "\n"; }
} // if (("states_" + select_xx) == menu_array[counter].id) else
} // for (counter=0; counter<menu_array.length; counter++)
if (debug_mode) { alert(menu_string); }
} // function ModifyDropdowns(select_xx)
</script>
This represents the initial drop-down menu:
<ul id="ul_XX" class="menu country">
<li id="select_XX" onclick="runTest(this.id);">Please Select Country of Residence</li>
<li id="us">United States</li>
<li id="gu">Guam</li>
<li id="pr">Puerto Rico</li>
<li id="um">United States Minor Outlying Islands</li>
<li id="vi">Virgin Islands, U.S.</li>
<li id="au">Australia</li>
<li id="ca">Canada</li>
<li id="va">Holy See (Vatican City State)</li>
<li id="ie">Ireland</li>
<li id="im">Isle of Man</li>
<li id="gb">United Kingdom</li>
<li id="vg">Virgin Islands, British</li>
</ul>
The <ul>
representing states within the "United States" is quite lengthy, so here are just snippets from the ones pertaining to the "United States Minor Outlying Islands" and "Virgin Islands, U.S.":
<ul id="ul_vg" class="menu state twoup">
<li id="select_vg" onclick="runTest(this.id)">Please Choose Island of Residence</li>
<li id="vg_AN">Anegada</li>
<li id="vg_VD">Jost Van Dyke</li>
<li id="vg_TO">Totola</li>
<li id="vg_VG">Virgin Gorda</li>
</ul>
<ul id="ul_vi" class="menu state twoup">
<li id="select_vi" onclick="runTest(this.id)">Please Choose Island of Residence</li>
<li id="vi_SC">Saint Croix</li>
<li id="vi_SJ">Saint John</li>
<li id="vi_ST">Saint Thomas</li>
</ul>
Please ensure that this JavaScript block follows your final second-level menu--for reasons unknown to me. :-(
<script type="text/javascript" >
function runTest(select_xx)
{
debug_mode = false;
const menuNode = document.getElementById("ul_" + select_xx.slice(-2));
if (debug_mode)
{
node_items = "<?php echo 'function index.php:runTest(select_xx) - '.__LINE__; ?>" + ":\n\n" ;
node_items += "select_xx = " + select_xx + "\n";
for (let count = 0; count < menuNode.length; count++)
{
node_items += "node[" + count + "] = " + menuNode[count].id + "\n";
} // for (let count = 0; count < nodeList.length; count++)
node_items += "\n" + "ul_" + select_xx.substr(-2);
alert(node_items);
} // if (debug_mode)
menuNode.addEventListener("click", (e)=>
{
debug_mode = false;
let listItemEl = e.target;
if (debug_mode) { alert("<?php echo 'function index.php:runTest(select_xx) - '.__LINE__; ?>:\n\n" + "listItemEl.id = " + listItemEl.id); }
if(menuNode.classList.contains("open")) { menuNode.prepend(listItemEl) };
listItemEl.closest("ul").classList.toggle("open");
ModifyDropdowns(listItemEl.id);
} // "click", (e)=>
) // ul_select_xx.addEventListener("click", (e)=>
} // function runTest()
</script>
A substantial amount of debugging was necessary to get this functioning correctly, and I've preserved some of the debugging code in case you find it useful--feel free to remove it from your code once everything works as intended.
To witness this code in action, visit
I trust that this information proves beneficial.