jQuery Style How to - Show and hide elements








Question

We would like to know how to show and hide elements.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<style type='text/css'>
div {<!--  w w  w  .  j  a  va  2s . co m-->
  display: table;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('div').css('display','none');
    $('button').on('click',function(){
        $('div').toggle();
    });
});
</script>
</head>
<body>
  <button>toggle</button>
  <div>table div</div>
</body>
</html>

The code above is rendered as follows: