[thelist] JS: retrieve element by tabindex value
Christian Heilmann
codepo8 at gmail.com
Wed Jan 18 16:22:58 CST 2006
> i have a form with tabindices set throughout... i need to get the id
> of the element with a tabindex of 401... ultimately, i'm trying to
> give that element focus...
>
> i have been all over google, and even found a couple scripts that
> just don't seem to be doing it...
Well, this might take a while, but how about looping through all
elements and reading the tabindex?
var allElm=document.getElementsByTagName("*");
for(var i=0;i<allElm.length;i++){
if(allElm[i].getAttribute('tabindex')==''){continue;}
if(allElm[i].getAttribute('tabindex')=='401'){var
elmID=allElm[i].getAttribute('id');break;}
}
might be faster with DOM1 reads and a variable:
var allElm=document.getElementsByTagName("*");
for(var i=0;i<allElm.length;i++){
tabidx=allElm[i].tabindex;
if(!tabidx || !tabidx!='401'){continue;}
if(tabidx=='401'){var elmID=allElm[i].getAttribute('id');break;}
}
--
Chris Heilmann
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
Binaries: http://www.onlinetools.org/
More information about the thelist
mailing list