show and hide nested divs using jquery
I am trying to hide and sow divs, I have done it in a primitiv way, and I want to do a smart function
the problem is that the inner divs doesn't shows
the functions name is
showdiv()
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>hide demo</title>
- <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
- </head>
- <body>
- <button id="div1show">show div1</button>
- <button id="div2show">Show div2</button>
- <a href="#" onclick="showdiv('div1');">Klicka här för div1</a></br>
- <a href="#" onclick="showdiv('div2');">Klicka här för div2</a>
- <div id="contentdiv" >
- <div id="div1" name="div1" class="inner" style="display:none;" background: "red">
- <span>Once</span> <span>upon</span> <span>a</span>
- <span>time</span> <span>there</span> <span>were</span>
- <span>three</span> <span>programmers...</span>
- </div>
- <div id="div2" name="div2" class="inner2" style="display:none;" background: "blue">
- <div id="login" class="inner2">
- <button id="btn">btn</button>
- </div>
- <p>text ... text</p>
- </div>
- </div>
- <script>
-
- function showdiv(toshow){
-
- $("#contentdiv div").hide("fast"); //Hide all divs
- //$( document.getElementById("div2")).show( "fast" );
- $("#" + toshow).show("fast"); //Show one specific div
- }
-
- $( "#div2show" ).click(function() {
- $( document.getElementById("div1") ).hide( "fast");
- $( document.getElementById("div2")).show( "fast" );
- });
- $( "#div1show" ).click(function() {
- $( document.getElementById("div2") ).hide( "fast");
- $( document.getElementById("div1")).show( "fast" );
- });
- </script>
-
- </body>
- </html>