Click to See Complete Forum and Search --> : which element has the focus


jasongr
08-20-2005, 04:41 PM
Hi

I am interested in finding out what element in the page has the focus. Is there a quick way to find out which element in the page current contains the focus?
I am looking for a solution that will work on both IE, Firefox and Opera.
If there is no element in focus (can such scenario happen?), then the code should return the document object in the DOM

regards

Charles
08-20-2005, 04:58 PM
JavaScript doesn't work that way but you might try something like <script type="text/javascript">
focusedElement = document;
onload = function () {
var e, i = 0;
while (e = document.getElementByTagName ('*')[i++]) {
e.onfocus = function () {focusedElement = this}
e.onblur = function () {focusedElement = document}
}
}
</script>

jasongr
08-21-2005, 01:46 AM
will the usage of the 'activeElement' property help me in some way?
does this property used also in firefox and opera?