User $window instead of window in getOnlySelectedElements.