jQuery HTML Element How to - Get native height of image








Question

We would like to know how to get native height of image.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.7.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--   www.  ja  v  a2s . c o m-->
    $(document).ready(function(){
       var imgheight = $('img').height();
       console.log(imgheight);
    });
});
</script>
</head>
<body>
  <img
    src="http://www.java2s.com/style/download.png" />
</body>
</html>

The code above is rendered as follows: