Move selection function out of event handler so it can be reused
Also apply selection function if the element is already focused on init