Check if the element is in the array before removing and adding classes