Tuesday, 3 June 2014

Show Hide Hidden Elements Using Javascript

There are many useful scripts that make any visible element on the page to by dynamically hidden or revealed with the aid of the CSS properties "visibility" and "display." in today's tutorial you will see the working example which you can use in web development any suitable purpose.
You can check here the working example here on this page.

Now You see Text

This is the Javascript Text Display example, which is only displayed on request...or Click Hide To hide from here.

  <script type="text/javascript">
      function cs(id) {
        if (e.style.display == 'none' || e.style.display == "") {
          e.style.display = 'block';
          d.innerHTML = 'Now Hide Again........';
        } else {
          e.style.display = 'none';
          d.innerHTML = 'Show Text Again';

Now adding some css for display of text
 #example1 {display: none; margin: 3%; padding: 4%; background-color: #F9F4BF}

Here comes the code text which you can place in between body of web page.
<div><a id="showhide"href="javascript:cs('example1')">Now You see Text</a>
<div id="example1"> This is the Javascript Text Display example, which is
only displayed on request...or <a id="showhide"href="javascript:cs('example1')">
Click Hide</a> To hide from here.</div>

If you have observe carefully ‘Now You see Text‘ is visible just once then only Now Hide Again & Show Text Again appear again. If you like the same text to appear and hide on clicking, again just comment on two lines in in javascript.
 //d.innerHTML = 'Now Hide Again.
// d.innerHTML = 'Show Again';

Another simple script you can use is
<script type="text/javascript">
function vb() {
function ab()

This has to be placed in between body
<a href="#" onclick="vb();"> Show </a>
<div id="a2" style="visibility:hidden;"><a href="#" onclick="ab();"> Hide</a>

Hope you find these codes short, simple and easy to remember, you may further customize as you like.


Post a Comment