Current location: Hot Scripts Forums » General Web Coding » JavaScript » Change <div> visibility

Change <div> visibility

Reply
  #1 (permalink)  
Old
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
Change <div> visibility

How do I get JS to change a <div> 's visibility,

I have:

<div id="main" style="visibility: show">

but I want a link like this

<a href="#" onclick="switchMain()">Change</a>

and clicking on that link will hide or show the layer.

I tried

Code:
 function getStyle()
   {
      var temp = document.getElementById("main").style.visibility;
  
      return temp;
   }

 function switchMain()
  {

      var current = getStyle();

      if( current == "show" )
       {
         document.getElementById("main").style.visibility = "hidden";
       }
       else
       {
         document.getElementById("main").style.visibility = "show";
       }
  }
but it doesnt work ? ?
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
It should be visible instead of show.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #3 (permalink)  
Old
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
doesnt make a difference
Reply With Quote
  #4 (permalink)  
Old
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
This works for me:
Code:
<html>

<head>
<script>
function getStyle()
   {
      var temp = document.getElementById("main").style.visibility;
  
      return temp;
   }

 function switchMain()
  {

      var current = getStyle();

      if( current == "visible" )
       {
         document.getElementById("main").style.visibility = "hidden";
       }
       else
       {
         document.getElementById("main").style.visibility = "visible";
       }
  }

</script>
</head>

<body>
<div id="main" style="visibility: visible">Hello</div>

<a href="#" onclick="switchMain()">Change</a>

</body>

</html>
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #5 (permalink)  
Old
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
yeah, got it thanks, I did some browser checking before hand..
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Been looking everywhere, onclick text change Drip Script Requests 0 11-27-04 01:03 AM
change IE search URL or change window registry sma JavaScript 1 04-26-04 02:40 PM
change IE search URL or change window registry sma PHP 0 04-26-04 05:38 AM
change color of the arrow +scrollbar in a FORM (+checkboard/radiobutton/..) detorre CSS 0 01-31-04 06:30 AM
Need ONE mouseover event to change TWO graphics on the page AccessGuy JavaScript 1 06-19-03 02:45 AM


All times are GMT -5. The time now is 09:44 AM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.