jQuery Style How to - Set height after calculation








Question

We would like to know how to set height after calculation.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.1.0.js'></script>
<style type='text/css'>
.sidebar-one {<!--from  w w w .j a va 2 s . c  o m-->
  height: 600px;
  background: red;
  width: 200px;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $(function() {
      var sidebar = $('.sidebar-one');
      sidebar.height(sidebar.height() - 135);
    });
});
</script>
</head>
<body>
  <div class="sidebar-one"></div>
</body>
</html>

The code above is rendered as follows: