How to get the width and height of an img element where width and height ha开发者_如何转开发ve not been set?
They don't have to be explicitly set by CSS:
var img = document.getElementById("my_img");
var height = img.height;
var width = img.width;
Just like that, you have the height and width of your image element.
Give an Id to the image(myImage) in the HTML and then ,
<img src="myimagejpg" id="myImage"/>
the following script will give the actuall height and width of the image...
var myImage = document.getElementById("myImage ");
var myheight= myImage .height;
var mywidth = myImage .width;
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论