I'm trying to apply focus to the element that had it last after a page load, like this:
lastFocus.container.focus();
where lastFocus is the jQuery element that had been focused on last before the page load.
When I first load the page, the user hasn't focused on anything, so I just set lastFocus to document.activeElement. It should be focusable, but the console throws Uncaught TypeError: Cannot call method 'focus' of undefined.
The strange thing is that even if I change the code so that it doesn't run on the initial load, the first time it tries to focus will always throw the error. Plus, the code always works after the error is thrown at least once. In fact, if I put the code inside a try...catch, the fields never achieve focus properly.