As written, our code is almost able to deal with more general cases, but not quite. There are three different elements of the class that are set statically, but we want to change them to make the class more generic.

We need to identify the item to be clicked and the item to be made visible. Our existing class also can only do one other thing in response to the click—it changes the text inside the button. So we’ll want some kind of callback to be executed on each click where we can add arbitrary behavior.

Here’s what I’ve got—again, there are a few different ways to do this, and the fact that I wrote the code this way doesn’t mean that there aren’t other perfectly valid ways:

Get hands-on with 1200+ tech skills courses.