<html>
<style>
div {
color: blue;
}
[tabindex="0"]{
color: red;
}
[tabindex="1"]{
color: green;
}
[tabindex="2"]{
color: yellow;
}
</style>
<script>
function clickme(){
var oButton = getButton();
var newAttribute = add();
oButton.setAttribute("tabindex", newAttribute);
}
function getButton(){
return document.getElementById("jerry");
}
function getNewCountFactory(){
var counter = 1;
return function(){
return (counter++) % 3;
};
}
var add = getNewCountFactory();
</script>
<button onclick="clickme()">Add</button>
<div>1</div>
<div id="jerry" tabindex="1">2</div>
</html>