Jump to content
xisto Community
Sign in to follow this  
iGuest

Toggle display in page script

Recommended Posts

This is my very first script, before I knew what was out there. It works in IE 5 and up. Not sure about netscape or mozilla. (I recently d/led mozilla and it's great for javascripts. Much less typing.)

<script language="javascript"><!--function toggle(what){  if(document.all[what].style.display == "none"){    document.all[what].style.display = "block";  }else{    document.all[what].style.display = "none";  }}//--></script><a href="javascript:toggle('myDiv')">Toggle</a><br><div style="display:none;" id="myDiv">  Some Text... Blah Blah Blah....</div>
This is what I can remember.

Share this post


Link to post
Share on other sites

document.all is a IE only DOM. Use this for the cross-browser version. I just changed the way to get the element.

<script language="javascript"><!--function toggle(what){  if(document.geElementById(what).style.display == "none"){    document.getElementById(what).style.display = "block";  }else{    document.getElementById(what).style.display = "none";  }}//--></script>

Use the same link/div.

Share this post


Link to post
Share on other sites

There is a shorter script to do that:

Function toggleId(id) {		element = document.GetElementById(id);		modus = (element.Style.Display == 'none' || element.Style.Display == '') ? 'block' : 'none';		element.Style.Display = modus;}

Share this post


Link to post
Share on other sites

Help with code

Toggle display in page script

 

Replying to unimatrix0

 

Hi,

 

I have used your code but found that I am unable to use it more than once on my web page. I have a few headings for which I want the text below it to appear and disappear.. I just copied and pasted the code a few times and changed the words but found it wasnt working.

 

How can I use the code given so that I can have a few headings on the page which will have different text appear and disappear?

 

Thanks for help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.