How to get image size (height & width) using JavaScript?

前端 未结 29 2999
忘了有多久
忘了有多久 2020-11-21 05:23

Are there any JavaScript or jQuery APIs or methods to get the dimensions of an image on the page?

29条回答
  •  攒了一身酷
    2020-11-21 05:52

    With jQuery library-

    Use .width() and .height().

    More in jQuery width and jQuery heigth.

    Example Code-

    $(document).ready(function(){
        $("button").click(function()
        {
            alert("Width of image: " + $("#img_exmpl").width());
            alert("Height of image: " + $("#img_exmpl").height());
        });
    });
    
    
    
    

提交回复
热议问题