首页javascriptwidthjQuery Style - 如何获取元素宽度和高度

jQuery Style - 如何获取元素宽度和高度

我们想知道如何获取元素宽度和高度。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.0.2.js'></script>
<script type='text/javascript'>
$(window).load(function(){
    var $img = $('.foo')
    var $width = $img.width();
    var $height = $img.height();
    console.log($width );
    console.log($height);
});
</script>
</head>
<body>
  <div class='foo'>foo</div>
</body>
</html>