View Full Version : Safari equivalent of document.activeElement.getAttribute
andynic
06-24-2009, 06:05 PM
Hi,
I have a function that uses both
document.activeElement.getAttribute('type');
document.activeElement.getAttribute('value');
It works perfectly in Internet Explorer, but not in Safari.
Does anyone know the equivalents for Safari?
Thanks,
Andynic
tianxz
06-24-2009, 09:12 PM
activeElement is only valid in IE. Firfox and safari should use currentTarget
metaslug001
09-29-2010, 03:26 PM
I've run some tests myself and found that activeElement is supported in the following browers:
Internet Explorer 9 (preview)
Internet Explorer 8
Internet Explorer 7
Internet Explorer 6
Firefox 4 (beta)
Firefox 3.6
Firefox 3.5
Firefox 3
Google Chrome 7
Google Chrome 6 (beta)
Google Chrome 5
Google Chrome 4
Safari 5
Safari 4
Opera 10
Opera 9
The only two browsers that I tested in which I couldn't get it working in were Firefox 2 and Safari 3... so while I wouldn't opt to call this object cross-browser-compatible, I also wouldn't rule out using it in the near future (once it's safe to say that no one is using FF2 and Safari 3 anymore). And I certainly wouldn't say it's only valid in IE.
I further did some testing with currentTarget, but maybe I'm using it wrong, as I always get an 'undefined' value for it when the page is done loading (whereas with my activeElement tests I would always get a returned value of '[object HTMLBodyElement]' because the body element has the focus once the page is done loading).
I read a bit about it and it seems to be used mostly in event listening, though I did see examples where it was used in the same syntax as activeElement (ie. document.currentTarget).
Maybe someone who is more knowledgable and experienced with this object can jump in and say a few words.
activeElement is only valid in IE. Firfox and safari should use currentTarget
Not really. document.activeElement was implemented in Firefox (starting with FF3) and Chrome, as part of the HTML5 specifications. Not in Safari, as far as I know.
For a Safari workaround, you may inspire yourself from:
http://ajaxandxml.blogspot.com/2007/11/emulating-activeelement-property-with.html
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.