Refactor this logic, you can use a function to handle the show/hide of the elements.