code to find which element is on focus

What is the code to judge if an element is on focus, and how to shift the focus to another element?