V Posted July 9, 2010 Share Posted July 9, 2010 I have a text that when click a a HTML form slides down. I'm trying to slide it back up when you click on the text again. The code that works is <script type="text/javascript"> $(document).ready(function(){ $("#slidedown").click(function() { $("#form").slideDown("fast"); }); }); </script> and now to slide it back up on click I tried toggle. Nothing happens tho.. <script type="text/javascript"> $('#slidedown').toggle( click(function() { $('#form').slideDown("fast"); }), click(function() { $('#form').slideUp("fast"); }); ); </script> Please anyone have any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/ Share on other sites More sharing options...
trq Posted July 9, 2010 Share Posted July 9, 2010 It appears you are missing the # hashs from the 'form' selectors. Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083319 Share on other sites More sharing options...
V Posted July 9, 2010 Author Share Posted July 9, 2010 Throbe, sorry it was a typo I made when posting. The code orginally has the # but doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083323 Share on other sites More sharing options...
trq Posted July 9, 2010 Share Posted July 9, 2010 Copy and Paste your actual code. We need your markup as well. Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083326 Share on other sites More sharing options...
trq Posted July 9, 2010 Share Posted July 9, 2010 Those clicks don't belong there. $('#slidedown').toggle( function() { $('#form').slideDown("fast"); }), function() { $('#form').slideUp("fast"); }); ); Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083327 Share on other sites More sharing options...
V Posted July 9, 2010 Author Share Posted July 9, 2010 Thanks throbe I tried without clicks but again nothing happens. This is the page code I use <div id="slidedown">+ Add New Category</div> <div id="form"> <form action="#" method="post"> <input type="text" id="cat" name="cat" size="14" /> <br /> <input type="submit" name="submit" id="button" class="submit" value="Add Category"> </form> </div> It works fine just sliding down. Sliding back up is the issue.. Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083330 Share on other sites More sharing options...
trq Posted July 9, 2010 Share Posted July 9, 2010 There was a few syntax errors. $(document).ready(function() { $('#slidedown').toggle( function() { $('#form').slideDown("fast"); }, function() { $('#form').slideUp("fast"); } ); }); Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083331 Share on other sites More sharing options...
V Posted July 9, 2010 Author Share Posted July 9, 2010 Thanks Thrope! It works perfectly now. Sometimes I consider JS way too compliocated and I overlook the minor errors.. Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083336 Share on other sites More sharing options...
trq Posted July 9, 2010 Share Posted July 9, 2010 Make sure you have firebug installed within FF and get a decent editor. Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083339 Share on other sites More sharing options...
V Posted July 9, 2010 Author Share Posted July 9, 2010 Will do! Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083342 Share on other sites More sharing options...
isedeasy Posted July 9, 2010 Share Posted July 9, 2010 untested but this should also work $(document).ready(function() { $('#slidedown').click( function() { $('#form').slideToggle("fast"); } ); }); Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083575 Share on other sites More sharing options...
V Posted July 9, 2010 Author Share Posted July 9, 2010 untested but this should also work $(document).ready(function() { $('#slidedown').click( function() { $('#form').slideToggle("fast"); } ); }); Yes that works too Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/207197-jquery-on-second-click/#findComment-1083646 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.