Javascript has the activeElement property which stores the last active element of a document but sometimes you need to only be concerned only with elements that can accept user input such as any input element, textarea or select element. After all, why would it be important to put focus back on an element that can't accept user input such as an h1 or paragraph element?