HELP !! STUCK in content addition !!

Discussion in 'JavaScript' started by harsh, Jan 10, 2009.

  1. #1
    Hello,
    I have a site www.anewraag.com. I want to add some good content on its home page in such a way that users see tht content when they click on content's heading, it means whenever someone clicks the heading or a "+" sign he should b able to expand and See the description of tht heading. Something like this.
    I don't know much scripting, i tried to do this myself through some online tutorial but didn't got much success.

    Please provide some guidance on this issue in detail.
    Thanks,
    Harsh
     
    harsh, Jan 10, 2009 IP
  2. yoavmatchulsky

    yoavmatchulsky Member

    Messages:
    57
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #2
    Try something like this:

    - put your content into a <div> element with a specific id.
    - set in your CSS file (or in inline styling) the display property to none.
    - write a javascript function which changes the display to 'block' when called
    - call that function on a click event

    HTML:
    
    <a href="#" onclick="toggleDisplay('exampleDiv'); return false;">Open content</a>
    <div id="exampleDiv" style="display:none;">
    CONTENT
    </div>
    HTML:
    JS:
    
    function toggleDisplay(id)
    {
      if (id == undefined) return;
      var elm = document.getElementById(id);
      if (!elm) return;
    
      elm.style.display = (elm.style.display == 'none' ? 'block' : 'none');
    }
    
    Code (markup):
     
    yoavmatchulsky, Jan 10, 2009 IP
    harsh likes this.
  3. harsh

    harsh Peon

    Messages:
    213
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the code. Rep added. :)
     
    harsh, Jan 12, 2009 IP