<!doctype html>
<html>
<body>
<img src="..." id="star">
<script>
star.onmousedown = function(event) {
alert()
};
</script>
</body>
</html>
Not my code, As you can see above the img with id="star" is being accessed as if it was an object, usually I would expect to do something either like
<img scr="..." onmousedown= myFunction() {...}>
Or
document.getElementById("star").onmousedown = myFunction() {...}
But somehow they just access the img directy via the id, I dont understand the syntax here, is this possible on any element with an id?
EDIT : If so when is there a use for the latter example?? eg. .getElementById(..)