'Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus'
I can resolve it by the code above. But not sure what I'm checking. I realise that first checking visibility of the input type ie whether it's hidden. Whether the style of the display is set to not display and whether that element has disabled. I'm not 100% certain about the second check the display. This fix works but would like to understand better what the 2nd check means.
Any help would be greatly appreciated.
The second one is to check if CSS's style.display property has been set to "none", which would mean that the component exists but is not displayed. I'm not sure if it's the correct way to check if you can set the focus or not. Do you intend to do it for all your focusable elements ?
thanks for the response. Yeah basically there is a bunch of html input types rendered on a page the code loops through to look for the first focusable input type and then gives focus to it. So this is the check to see what is focusable. Have tried element.focus != null but this didn't work. Do I make sense?
Andrey V. Ovcharenko wrote:You can check up in addition property "visibility". However, the parent of an element can be invisible. Therefore, the call of a method "focus" is better for concluding in the block "try".
Thanks Andrey, try/catch the method of focus is the simplest way to fix the IE bug! DO NOT use so many if judgement, who works well will work well, let it to be!
In 1.6.x we trapped and discarded *any* errors thrown by an inline event handler.
That is not good because it masks problems that the handler may have.
We are trying to remove any of these omnibus try/catch situations in the jQuery code base to prevent that.
So this error was occurring before, but just masked.
I think IE8 is justified in being upset that you're trying to set focus to an element the user cannot see or interact with.
Most other browsers seem to ignore it since it's not a valid request, but there's no W3C guideline that I know of for what to do when someone asks to focus an invisible element.
An error is probably better than silence when it comes to debugging.
If this is being caused by a plugin then the plugin should be fixed.
Solutions include showing the element before setting focus to it, or using .triggerHandler() if you just want to run handlers and not actually set focus.
This resolution seems a bit strange to me, but perhaps I don't quite understand jQuery goal.
From where I stand - jQuery is suppose to provide consistent behaviour across browsers and this is not it.
jQuery provides consistent behavior for a valid set of inputs and actions.
Trying to focus an invisible element isn't in that set.
Making things consistent across browsers shouldn't mean making all browsers hide an mistake if any of them hide the mistake.