Get height of image inside a hidden div

前端 未结 9 640
自闭症患者
自闭症患者 2021-01-02 18:50

i want to to get the height/width of an image inside a hidden div-containter, but .height() and .width() both returns 0 (like expected).

         


        
9条回答
  •  情深已故
    2021-01-02 19:00

    Its because the image has not loaded yet.....

    $('body').append('
    '); $('#init').hide(); $('#myimg').bind("load",function(){ alert(this.height) //works })​

    heres a test: http://jsfiddle.net/WMpSy/

提交回复
热议问题