Show/hide content

Discussion in 'JavaScript' started by common2, Jul 13, 2009.

  1. #1
    Hi all
    I am struggling with show/hide content. I have Xampp on my home computer which does not have a problem with the following code, but when I upload it to a host server, it does not hide the second division...can someone tell me whats wrong please?!!

    this is the code i have in my head section:
    <script language="javascript" type="text/javascript"> 
    function emailcon(shID) 
    {
         if (document.getElementById(shID+'-show').style.display != 'none') 
        {
            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID+'-hide').style.display = 'block';
        }
        else
        {
           document.getElementById(shID+'-show').style.display = 'inline';
           document.getElementById(shID).style.display = 'none';
        }
    
    </script>
    HTML:
    this is the code in my body:
    
    <div class='less' id="email-show">
            some text
    </div>
    								 <div id="email-hide" class="more">
          something else
    </div>
    HTML:
    and in my stylesheet i have .class{display:none;}
     
    common2, Jul 13, 2009 IP
  2. zeronese

    zeronese Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i just see that you missed the '-hide' in
    document.getElementById(shID).style.display = 'none';

    note: this is an overlook, i did not test the code
     
    zeronese, Jul 14, 2009 IP
  3. Martinoes

    Martinoes Peon

    Messages:
    110
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Fixed.

    <script language="javascript" type="text/javascript"> 
    function emailcon(shID) 
    {
         if (document.getElementById(shID+'-show').style.display != 'none') 
        {
            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID+'-hide').style.display = 'block';
        }
        else
        {
           document.getElementById(shID+'-show').style.display = 'inline';
           document.getElementById(shID+'-hide').style.display = 'none';
        }
    
    </script>
    PHP:
     
    Martinoes, Jul 29, 2009 IP
  4. PhpRay

    PhpRay Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This code is so interesting for me.. could you paste here the whole code to understand how can I add it in the right way at my html/css script please?
     
    PhpRay, Jul 29, 2009 IP