I have a list with 250 countries in a HTML dropdown(for the sake of space I've only included 5 below):
<select name="postalCountry" class="valid">
<option value="AF">Afghanistan</option>
<option value="AX">Aland Islands</option>
<option value="AK">Alaska</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
Unfortunately I cannot edit the HTML element themselves, so I was wondering if there is a way to hide all of them except for Alaska (value=AK) using Javascript?
I currently have the following:
var country = document.querySelectorAll('select[name="postalCountry"] option');
var e;
for (e = 0; e < country.length; e++){
country[e].style.display = 'none';
}
country[2].style.display = 'initial';
But that gets a bit messy since I would have to go through a lot of countries to find out the index number of a country at the end of the list.
Any suggestion is greatly appreciated !
map, which on a list that small won't make much of a difference in performance anyway.<option>in some browsers notably IE. You have to remove or disable.map()on. And why a method to translate every element into another one if the purpose is to only change one attribute of the elements?