jQuery Animation How to - Dynamically expand div upon hiding another








Question

We would like to know how to dynamically expand div upon hiding another.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<style type='text/css'>
#container {<!--   w w w. j  a  v a2  s .  c om-->
  height: 200px;
  width: 870px;
  float: left;
  margin: 0;
  padding: 0;
}

.col {
  height: 200px;
  width: 32%;
  float: left;
  border-width: 0.5mm;
  border-style: groove;
  -moz-border-radius: 15px;
  border-radius: 15px;
}
</style>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$(document).ready(function(){
  $('.col').click(function(){
    $(this).css("display","none");
    $('.col').css("width","49%");
    $('.col').css("width","49%");
  })
});
});//]]>  
</script>
</head>
<body>
  <div id="container">
    <div class="col">
      <p>click to hide</p>
    </div>
    <div class="col">
      <p>click to hide</p>
    </div>
    <div class="col">
      <p>click to hide</p>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: