Possible Duplicate:
IE/Chrome: are DOM tree elements global variables here?
I am currently working on a mobile site using jquery mobile and I noticed something interesting (to me anyway, as I am still new to js). Inside a function, you can reference an element with just the id.
This is the test code I used (on chrome 22.0.x, firefox 16.0.1, and safari 5.1.7):
<!DOCTYPE html>
<html>
<head></head>
<body onload="tt()">
<div id="abc">Test</div>
<a id="cba">Test2</a>
</body>
<Script>
function tt() {
console.log(abc);
abc.style.backgroundColor = "red";
return cba;
}
</Script>
</html>
No getElementById, no jquery selector, just the id. Has it always been this way? If so, is this a good practice and why does this work? I am thinking function must have a context, but where is it, is it the page?
Any insight would be appreciated, Thanks.