Look at the following JS code:
alert(myImgId.src);
and corresponding HTML:
<img id="myImgId" src="http://images4.wikia.nocookie.net/__cb20121128141533/logopedia/images/6/6f/Superman_logo.png"></img>
What I expect would happen:
A javascript error specifying that it cannot find variable myImgId
, basically a sort of NPE while accessing object src
of myImgId
.
What actually happens: Modern browsers(FF 17 & above, chrome) pick up the DOM element with the given ID automatically. Older versions of browsers like FF 10 throw an error as expected.
Can somebody explain what is happening over here?