Added condition to check for a selector before calculating it's position