<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>"autofocus" in XHTML and the focus() method</title> <style> input, input#test:focus { background:lime } input#test, input:focus { background:red } </style> <script language="JavaScript" type="text/javascript"> function log(message) { document.getElementById("console").innerHTML += "<li>"+message+"</li>"; } function test() { document.getElementsByTagName('input')[0].focus(); if (window.testRunner) testRunner.dumpAsText(); if (document.activeElement == document.getElementsByTagName('input')[0]) log("SUCCESS"); else log("FAILURE"); } </script> </head> <body onload="test()"> <p>The form controls below should have a green background:</p> <p><input id="test"/></p> <p><input autofocus="autofocus"/></p> <p><input autofocus="autofocus"/></p> <hr/> <ol id="console"></ol> </body> </html>