My HTML code is as follows:
<a href="index.php"><img id="testimg" src="images/logo.png"/></a>
This is my JavaScript code:
function getW(){
var theImg = document.getElementById('testimg');
return theImg;
}
theImg = getW();
if (theImg.width > 119){
document.write(theImg.width);
}
When I run this script, it outputs the width of the image.
However, when I use the following script:
function getW(){
var theImg = document.getElementsByTagName("img");
return theImg;
}
theImg = getW();
if (theImg.width > 119){
document.write(theImg.width);
}
It does not output anything. What could be the reason for this difference in behavior between the two scripts?
Thank you!