Results 1 to 3 of 3

Thread: Collapsing show() and hide() functions into one?

  1. #1
    Join Date
    May 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Collapsing show() and hide() functions into one?

    I'm using the following script to show/hide a particular element on my website. How would I collapse these two functions into one?

    (if hidden, unhide. if visible, hide)

    Code:
    function show(){
    document.getElementById("live").style.visibility="visible"
    }
    
    
    function hide(){
    document.getElementById("live").style.visibility="hidden"
    }

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    function showhide(){
    var el=document.getElementById('live').style;
    el.visibility=el.visibility=='hidden'? 'visible' : 'hidden';
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you!! ^^

    I wanted to use this for several elements so I modified it a bit. This is the final snippet:

    Code:
    function showhide(id){
    var el=document.getElementById(id).style;
    el.visibility=el.visibility=='hidden'? 'visible' : 'hidden';}
    </script>
    Last edited by Mistrel; 05-15-2006 at 08:31 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •