I have a bunch of HTML set up like so:
<button class="btns">Button A</button>
<ul class="unorder-list" aria-hidden="true">
<li>List</li>
<li>List</li>
</ul>
<button class="btns">Button B</button>
<ul class="unorder-list" aria-hidden="true">
<li>List</li>
<li>List</li>
</ul>
So all the buttons are visible but all the <ul>
are hidden. When a button is clicked, I want it to toggle the adjacent <ul>
to show and another click to hide.
I am have some code like so that puts the event listener for the button click event but need to do what is mentioned above and adjust the aria-hidden attribute to false.
var e, divs = document.getElementsByClassName('btns');
var index = 0;
var ul = document.getElementsByClassName('unorder-list');
// var list
for (e in divs) {
var i = e;
if (divs.hasOwnProperty(e)) {
divs[e].onclick = function() {
// Returns 'namedItem'
alert(e);
// Returns undefined
alert(ul[index]);
// Error
var visible = ul[index].style.display;
// Do work here to show/hide and adjust attributes as needed
alert(visibile);
// document.getElementById(id).style.display = 'block';
};
index++;
}
}
I am writing this to make sure the code is well-formed and accessible.