Instructor: Today, we are creating an accessible pop up button. We'll be using this button that says, "Helpful links to open and close this unordered list of links." In the markup, we have a button with the class pop-upopen and that has the inner text helpful links. Then we have an unordered list with the class pop-upitems. Then we have three list items with links.
A lot of times when people want to show something is open or closed, they'll add a class open and then use the styling that way. Today, we're going to make it a little bit more semantic and use aria-expanded.
Now we have the aria-expanded = false on that button. We will add an event listener onto that show button and it's going to be a click event listener. We'll create an arrow function here. Before I toggle anything, I'm going to create a variable called aria-expanded and just grab that value of that attribute.
As a note, this will return a string and not a Boolean, which is why I'm not going to do if aria-expanded because that's not going to work. I will say if aria-expanded = "true," then we are going to show button, set attribute aria-expanded false.
Then, we are going to do an else statement. Basically, I'm going to copy and paste and do the opposite. If we refresh this page, you can see that this is toggling true and false.
Now, let's test it on a screen reader in Safari.