How do I know which element has the focus, or how to determine whether the focus of a particular element?
2 Answers
I don't know of anyway to query for this kind of information directly. I suppose you could traverse the DOM and check for it manually. If that's the case you should look at this.
Perhaps what you are trying to do can be achieved by handling an event when specific elements of interest gain focus. Here is how you would do that in jQuery.
$('<selector>').focus(function() {
// Do something here
});
Just for giggles, here is one way you could use the focus method to track which element recieved it last. I highly recommend against using this code.
var gotDaFocus;
$('*').focus(function() {
gotDaFocus = this;
});

- 1
- 1

- 9,217
- 5
- 38
- 41
-
-
Errr... Sorry :). You might want to update the question to state that. I just assumed JS because of the key words "element" and "focus". I didn't look at the tags. Good luck. – Blake Taylor Apr 13 '11 at 14:25
not yet implemented yet i'm afraid. You could do something like this
Shoes.app do
@focused = para ""
stack do
@label1 = edit_line :text => 1
click do
@focused.replace @label1.text
end
end
stack do
@label2 = edit_line :text => 2
click do
@focused.replace @label2.text
end
end
end
But the problem in windows is that the controls steal all the event from Shoes. In Green Shoes it would work. If you'r in windows you can still see the result if you click just to the right of the edit_line. Of course, this is only when you click with the mouse, you should check keypress tot get the keyboard events also. Grtz

- 41,770
- 5
- 64
- 108