Results 1 to 6 of 6

Thread: Modify jscript show/hide div...?

  1. #1
    Join Date
    Jul 2006
    Posts
    64
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default Modify jscript show/hide div...?

    Right now the current script shows and hide's two divs... it works fine but it does not hide an open div when the other one is shown. basically only one div should be own at a time. can anyone asist with helping me add that piece of coding?

    Code:
    <!-- display Forms -->		
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    function ShowHide1(){
    $("#slidingDiv1").animate({"height": "toggle"}, { duration: 100 });
    }
    function ShowHide2(){
    $("#slidingDiv2").animate({"height": "toggle"}, { duration: 100 });
    }
    //]]>
    </script>
    
    <a onclick="ShowHide1(); return false;" href="#">Section 1</a> 
    <a onclick="ShowHide2(); return false;" href="#">Section 2</a>
    		
    		
    <div id="slidingDiv1" style="display:none;">
    THIS is for Section 1 <a onclick="ShowHide1(); return false;" href="#">hide</a>
    </div>
    
    <div id="slidingDiv2" style="display:none;">
    This is for Section 2 <a onclick="ShowHide2(); return false;" href="#">hide</a>
    </div>
    <!-- /display Forms -->

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Code:
    <!-- display Forms -->		
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    function ShowHide1(){
    $("#slidingDiv1").animate({"height": "toggle"}, { duration: 100 });
    if($("#slidingDiv2").css('display','block')){
      $("#slidingDiv2").slideUp({ duration: 100 });
    }
    }
    function ShowHide2(){
    $("#slidingDiv2").animate({"height": "toggle"}, { duration: 100 });
    if($("#slidingDiv1").css('display','block')){
      $("#slidingDiv1").slideUp({ duration: 100 });
    }
    }
    //]]>
    </script>
    
    <a onclick="ShowHide1(); return false;" href="#">Section 1</a> 
    <a onclick="ShowHide2(); return false;" href="#">Section 2</a>
    		
    		
    <div id="slidingDiv1" style="display:none;">
    THIS is for Section 1 <a onclick="ShowHide1(); return false;" href="#">hide</a>
    </div>
    
    <div id="slidingDiv2" style="display:none;">
    This is for Section 2 <a onclick="ShowHide2(); return false;" href="#">hide</a>
    </div>
    <!-- /display Forms -->
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    acctman (03-15-2010)

  4. #3
    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

    How about (Note: Requires jQuery 1.4x as indicated in the external script tag):

    Code:
    <!-- display Forms -->		
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript">
    //<![CDATA[
    jQuery(function($){
    	var c = $('.contentDivs'), a;
    	$('.showHide').bind('click', function(e){
    		e.preventDefault();
    		c.slideUp(200);
    		if((a = $(this).attr('href')) === '#hide'){
    			return;
    		}
    		$(a).delay(100).slideDown(300);
    	});
    });
    //]]>
    </script>
    
    <a class="showHide" href="#slidingDiv1">Section 1</a> 
    <a class="showHide" href="#slidingDiv2">Section 2</a>
    		
    		
    <div class="contentDivs" id="slidingDiv1" style="display:none;">
    THIS is for Section 1 <a class="showHide" href="#hide">hide</a>
    </div>
    
    <div class="contentDivs" id="slidingDiv2" style="display:none;">
    This is for Section 2 <a class="showHide" href="#hide">hide</a>
    </div>
    <!-- /display Forms -->
    - John
    ________________________

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

  5. #4
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hi i am new here at this forum... what does this code for?

  6. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    What does this sentence mean for?
    Jeremy | jfein.net

  7. #6
    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

    Quote Originally Posted by bozimitz View Post
    hi i am new here at this forum... what does this code for?
    It (from my previous post in this thread) slides content in and out of view on the page. Just copy it exactly as it is, save it as whatever.htm. and try it out, you'll see.
    - John
    ________________________

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

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
  •