fixes bug when element is selected and hidden