for(var i=0;i<tr.length;i++){
var td = tr[i].getElementsByTagName("td");
if(td[2].innerHTML==time && td[3].innerHTML==cls){
td[0].setAttribute("id","focus");
tr[i].style.backgroundColor="green";
var foc = document.getElementById("focus");
foc.focus();
cnt++;
}
else{
tr[i].style.backgroundColor="transparent";
}
}
This is a year too late, but you CAN focus to a TD element. Just give it a tabindex property, and then do a focus().
This works for DIV elements and almost all others.
I've tried this on Firefox 3.5 and up.
As the question is about changing the focus on a TD or TR, then the answer is that you cannot focus on such HTML tags; you can change the currently focused element if that is a input element (textarea, textfield, checkbox, radios) or a link, which are highlighted in a particular way when you click the key tab.
If you are really trying to focus on an input field, as suggested by Jonathan Sampson, then the answer he gave is the correct one.
In your code you are really trying to get the focus on a tag TD, then the answer to the question is no.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With