saving position of element only if condition is met