CSS/JS - Div show hide

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BradM
    Confirmed User
    • Dec 2003
    • 3397

    #1

    CSS/JS - Div show hide

    I need a script that will allow me to show hide content inside of a div. I managed to get one working fine, super simple - but my JS sucks so I can't build on it.

    I need for when you click a SECOND link the div opens and closes any other opened divs of the same class/ID. So basically just a tab system. Anyone have a super simple one available?
  • StuartD
    Sofa King Band
    • Jul 2002
    • 29903

    #2
    function showDiv(x){
    if(document.getElementById(x).style.display == 'none'){
    document.getElementById(x).style.display = '';
    }
    else {
    document.getElementById(x).style.display = 'none';

    }
    }

    <input type="button" onclick="showDiv('divname');">

    That one won't work the other "tabs" but it's pretty easy to add in....
    This is me on facebook
    This is me on twitter

    Comment

    • BradM
      Confirmed User
      • Dec 2003
      • 3397

      #3
      yea that's pretty much what I have already. it keeps the old div open when you click a new one. means if I have 19 elements, they all get stacked. I want to close previous ones when a new one is opened.

      Comment

      • harvey
        Confirmed User
        • Jul 2001
        • 9266

        #4
        http://fdsign.com/jeff/ams-final2/products.html

        choose a product and click "supplement facts" to see it work

        code:

        Code:
        <SCRIPT LANGUAGE="JavaScript">
        function showElement(element)
        {
        var target = document.getElementById(element);
        target.style.display='block';
        }
        function hideElement (element)
        {
        var target = document.getElementById(element);
        target.style.display='none';
        }
        </SCRIPT>
        and this is the code to place it (too lazy and busy to clean it, so see by yourself)

        Code:
        <DIV Name="id2" ID="id2" style="display:none; width:98%;height:auto;position:middle center;z-index:100;">
        <img src="1-DAfacts.jpg" /> <div style="clear:both;background-color:#444444;border:1px #FFF solid;font-size:12px;font-weight:bold;padding:3px;"><A HREF="#nowhere" onclick="hideElement('id2');"><img style="padding:4px; border:0;"src="close.gif" /></A></div></DIV>
        
        	<div class="pic"><img src="androsterone.jpg" alt="Androsterone" style="padding-left:5px;"/><a href="faq.html"><p><img src="faq.gif" alt="Frequently Asked Questions" style="border:0; padding-top:15px;"/></a></p><A HREF="#nowhere" onclick="showElement('id2');"><img src="supplement.gif" alt="Supplement Facts" style="border:0; padding-top:15px;"/></a></p></div>
        basically give an ID to the div you want to show/hide and then hideElement('id2'); to hide and showElement('id2'); to show, very simple but effective
        This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth

        Comment

        • fris
          I have to go potty
          • Aug 2002
          • 55751

          #5
          check out mootools

          http://demos111.mootools.net/
          Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


          Totally Free Templates

          Comment

          • Deej
            I make pixels work
            • Jun 2005
            • 24386

            #6
            I think i just made a mess in my pants...

            CSS and JS makes me hard!

            Deej's Designs n' What Not
            Hit me up for Design, CSS & Photo Retouching


            Icq#30096880

            Comment

            • Bird
              Confirmed User
              • Jan 2005
              • 4365

              #7
              Try changing the z-layer
              ICQ:268731675

              Comment

              • woj
                <&(©¿©)&>
                • Jul 2002
                • 47880

                #8
                If you happen to use dreamweaver cs3, search for spry tutorial on youtube, it's super easy to setup even for someone who doesn't know shit about javascript...
                Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
                Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
                Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

                Comment

                • GrouchyAdmin
                  Now choke yourself!
                  • Apr 2006
                  • 12085

                  #9
                  Originally posted by Bird
                  Try changing the z-layer
                  I don't know why, but I smirked for some reason.

                  Comment

                  • acctman
                    Confirmed User
                    • Oct 2003
                    • 2840

                    #10
                    www.dynamicdrive.com should have what you're looking for, and if they dont they'll custom tweak stuff in the forum for you. very helpful site and users helping each other out

                    Comment

                    • BigBen
                      Confirmed User
                      • Nov 2004
                      • 2299

                      #11
                      I use jquery for stuff like that. Sounds like you're looking for something like this... http://docs.jquery.com/UI/Accordion

                      I've tried mootools and prototype and like jquery the most. Even if you aren't great with JS, this helps a ton.

                      Comment

                      • harvey
                        Confirmed User
                        • Jul 2001
                        • 9266

                        #12
                        Originally posted by harvey
                        http://fdsign.com/jeff/ams-final2/products.html

                        choose a product and click "supplement facts" to see it work

                        code:

                        Code:
                        <SCRIPT LANGUAGE="JavaScript">
                        function showElement(element)
                        {
                        var target = document.getElementById(element);
                        target.style.display='block';
                        }
                        function hideElement (element)
                        {
                        var target = document.getElementById(element);
                        target.style.display='none';
                        }
                        </SCRIPT>
                        and this is the code to place it (too lazy and busy to clean it, so see by yourself)

                        Code:
                        <DIV Name="id2" ID="id2" style="display:none; width:98%;height:auto;position:middle center;z-index:100;">
                        <img src="1-DAfacts.jpg" /> <div style="clear:both;background-color:#444444;border:1px #FFF solid;font-size:12px;font-weight:bold;padding:3px;"><A HREF="#nowhere" onclick="hideElement('id2');"><img style="padding:4px; border:0;"src="close.gif" /></A></div></DIV>
                        
                        	<div class="pic"><img src="androsterone.jpg" alt="Androsterone" style="padding-left:5px;"/><a href="faq.html"><p><img src="faq.gif" alt="Frequently Asked Questions" style="border:0; padding-top:15px;"/></a></p><A HREF="#nowhere" onclick="showElement('id2');"><img src="supplement.gif" alt="Supplement Facts" style="border:0; padding-top:15px;"/></a></p></div>
                        basically give an ID to the div you want to show/hide and then hideElement('id2'); to hide and showElement('id2'); to show, very simple but effective
                        I took the sample down due to client's request, so try the code by yourself, it's foolproof without knowing shit of JS, even I can use it
                        This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth

                        Comment

                        Working...