Can't use jQuery or CSS (only). I have:
function handleDropDown (elementId) {
document.getElementById('languages').style.display = "block";
}
.flag-icon-wrapper {
margin-right: 20px;
padding-top: 5px;
}
.flex {
display: flex;
}
.flag-icon {
width: 50px;
}
.is-hidden-initially {
display: none;
}
<span class="flag-icon-wrapper flex" onClick='handleDropDown()'>
<img class="flag-icon" src="https://i.imgur.com/3DpAxu5.png" />
</span>
<div class="languages is-hidden-initially">
<ul>
<li>Spanish</li>
<li>French</li>
<li>Russian</li>
</ul>
</div>
The idea is that when you click on the American flag, it should reveal a list of other languages (eventually to choose from). Eventually, when you click on another language, I'd like to show the flag that's associated with that language in the flag-icon-wrapper span, but for now, I just want to show or hide the languages div when you click on the flag.
At this point, I'm getting Uncaught TypeError: Cannot read property 'style' of null" - why? I'm getting the element by ID languages to display it as block - so why is that part not working? Thanks
EDIT It's now fixed by changing the class to an ID in the html:
<span class="flag-icon-wrapper flex" onClick='handleDropDown()'>
<img class="flag-icon" src="https://i.imgur.com/3DpAxu5.png" />
</span>
<div id="languages" class="is-hidden-initially">
<ul>
<li>Spanish</li>
<li>French</li>
<li>Russian</li>
</ul>
</div>
But now how can we toggle between showing and hiding the div?
id. You've set theclassto "languages", not theid.