Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question error in simple hide/show text in javascript

    Code:
    <html>
    <title> random!!</title>
    <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="jquery.min.js"></script>
    </head>
    <body>
    <div class="one" style="cursor: pointer;">
    type1<br/><br/></div><div class="two" style="cursor: pointer;">type2<br/><br/></div><div class="three" style="cursor: pointer;">type3<br/><br/></div>
    <div class="oneone">atrdjgkhgfyfygfykfyfkygfvkgvkhgv</div><div class="twotwo">hgfihygohgohsgoihgolhgshgoshdgchchj</div><div class="threethree">siucgdiuhsbcohbscjbsidjcksjdnck</div>
    
    <script type="text/javascript"> 
    $(document).ready(function() 
    { 
    $('div.twotwo').hide();
    $('div.threethree').hide(); 
    $('div.one').toggle(function() 
    {
    $('div.twotwo').hide();
    $('div.threethree').hide();
    $('div.oneone').fadeIn('slow'); 
    }, function() 
    { 
    return false; 
    }); 
    
    $('div.two').toggle(function() 
    {
    $('div.oneone').hide();
    $('div.threethree').hide();
    $('div.twotwo').fadeIn('slow'); 
    }, function() 
    { 
    return false; 
    }); 
    
    $('div.three').toggle(function() 
    {
    $('div.twotwo').hide();
    $('div.oneone').hide();
    $('div.threethree').fadeIn('slow'); 
    }, function() 
    { 
    return false; 
    }); 
    });
    </script>
    </body>
    </html>
    The following code works perfectly when clicked once in each of the sub divisions(type1, type2, type3) for hide/show. But from the next time onwards we will have to click twice to initiate the hide/show. Can anyone suggest changes to make the code work as desired??.. P.S: sorry if i have made any stupid mistake.. i am quite new to this!!

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,395
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Hm this is weird ... I did not find any .toggle() method in jQuery that takes two callback functions. The normal usage is
    Code:
    .toggle(duration, [easing, [callback]])
    Which means, the first parameter has to be a number or string determining the speed of the toggle process. So I guess your usage is flawed.


  •  

    LinkBacks (?)


    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •