Refactored updateVisibility

Removed unnecessary var declarations and merged two function calls into
a single chained call; also changed the var selected to be based on the
id of the element instead of its text