Javascript Style How to - Show/hide element








Question

We would like to know how to show/hide element.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<style type='text/css'>
#myID {<!--  w  w w .  j  a  v a 2 s .c  om-->
  display: block;
  background: #006;
  color: #fff;
  width: 200px;
  text-align: center;
}
</style>
</head>
<body>
  <a href="javascript:void(0);" onclick="$('#myID').toggle();">Toggle</a>
  <a href="" id="myID">java2s.com</a>
</body>
</html>

The code above is rendered as follows: