if you want change focus depending on other event (like click event) you can say as the following :
ElementsNumber = document.getElementsByTagNam('*') ;
/* or you can say ElementsNumber = document.getElementById('foo'); where foo
is the container of the elements that you want to toggle focus between*/
var x = 0 ;
function changeFocus()
{
ElementsNumber[x].focus();
++x ;
}
document.getElementById('focus-button').onclick = changeFocus()
// where the 'focus-button' is the element which you want to change focus if it clicked
but don't try to give focus to all elements (or a group of them) at the same time , Focus event can't be triggered for more than one element at once , you can find a lot information about this "fact" in Mozila Developers Network (MDN) , however you can give focus to the whole document :
$(document).focus(); //jquery
window.focus(); // pure javascript
or you can loop through html Dom as the following :
ElementsNumber = document.getElementsByTagNam('*') ;
for ( i = 0 ; i < ElementsNumber.length ; i++ )
{
// somethings to be done to all elements
}
and this will give focus to all elements . but if you want change focus to the elements respectively at an specified interval you can use setInterval() function as the following :
ElementsNumber = document.getElementsByTagNam('*') ;
var x = 0 ;
function changeFocus()
{
ElementsNumber[x].focus();
++x ;
}
setInterval(function(){ changeFocus(); }, 3000);
and this will change focus to the next element in the dom every 3 seconds .
I hope this answer is the one you are after ...