jQuery Style How to - Set element width and height








Question

We would like to know how to set element width and height.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.6.js'></script>
<style type='text/css'>
div {<!-- w  ww  .j a  v  a  2 s .c om-->
  height: 100px;
  background: blue
}
</style>
<script type='text/javascript'>
$(function(){
    $('div').css({
        'width': 'auto',
        'height': '500px'
    });
});
</script>
</head>
<body>
  <div>hello</div>
</body>
</html>

The code above is rendered as follows: